summaryrefslogtreecommitdiffstats
path: root/core/java/com/android/internal/app/ResolverProxy.java
blob: f59fd11f457181522ddcd0a4239f95835e88a3e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * Copyright (C) 2016 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.app;

import java.util.List;
import android.content.pm.ResolveInfo;
import android.content.Context;
import android.content.Intent;
import android.widget.AbsListView;
import android.app.VoiceInteractor.PickOptionRequest.Option;
import com.android.internal.app.ResolverActivity.TargetInfo;

/** Relax access modifiers on key ResolverActivity extension methods to allow
    them to be overridden from a different package/classloader.
    Used by CMResolver */
public class ResolverProxy extends ResolverActivity {
    private static final String TAG = "ResolverProxy";

    /** If the superclass may set up adapter entries after onCreate completes,
        This method should be overridden to do nothing, and
        sendVoiceChoicesIfNeeded should be called once the adapter setup is
        complete. */
    @Override
    protected void onSetupVoiceInteraction() {
        super.onSetupVoiceInteraction();
    }

    /** see onSetupVoiceInteraction */
    @Override
    protected void sendVoiceChoicesIfNeeded() {
        super.sendVoiceChoicesIfNeeded();
    }

    @Override
    protected int getLayoutResource() {
        return super.getLayoutResource();
    }

    @Override
    protected void bindProfileView() {
        super.bindProfileView();
    }

    @Override
    protected Option optionForChooserTarget(TargetInfo target, int index) {
        return super.optionForChooserTarget(target, index);
    }

    @Override
    protected boolean shouldGetActivityMetadata() {
        return super.shouldGetActivityMetadata();
    }

    @Override
    protected boolean shouldAutoLaunchSingleChoice(TargetInfo target) {
        return super.shouldAutoLaunchSingleChoice(target);
    }

    @Override
    protected void showAppDetails(ResolveInfo ri) {
        super.showAppDetails(ri);
    }

    @Override
    void startSelected(int which, boolean always, boolean filtered) {
        super.startSelected(which, always, filtered);
    }

    @Override
    protected void onActivityStarted(TargetInfo cti) {
        super.onActivityStarted(cti);
    }

    @Override
    protected boolean configureContentView(
            List<Intent> payloadIntents, Intent[] initialIntents,
            List<ResolveInfo> rList, boolean alwaysUseOption) {
        return super.configureContentView(
                payloadIntents, initialIntents, rList, alwaysUseOption);
    }

    @Override
    protected void onPrepareAdapterView(
            AbsListView adapterView, ResolveListAdapter adapter, boolean alwaysUseOption) {
        super.onPrepareAdapterView(adapterView, adapter, alwaysUseOption);
    }

    /** subclasses cannot override this because ResolveListAdapter is an inaccessible
        type. Override createProxyAdapter(...) instead */
    @Override
    ResolveListAdapter createAdapter(Context context, List<Intent> payloadIntents,
            Intent[] initialIntents, List<ResolveInfo> rList, int launchedFromUid,
            boolean filterLastUsed) {
        ProxyListAdapter adapter = createProxyAdapter(
            context, payloadIntents, initialIntents, rList, launchedFromUid, filterLastUsed);
        return (adapter != null)
            ? adapter
            : super.createAdapter(context, payloadIntents, initialIntents,
                                  rList, launchedFromUid, filterLastUsed);
    }

    /** Subclasses should override this instead of createAdapter to avoid issues
        with ResolveListAdapter being an inaccessible type */
    protected ProxyListAdapter createProxyAdapter(Context context, List<Intent> payloadIntents,
            Intent[] initialIntents, List<ResolveInfo> rList, int launchedFromUid,
            boolean filterLastUsed) {
        return null;
    }

    protected void setAlwaysUseOption(boolean alwaysUse) {
        mAlwaysUseOption = alwaysUse;
    }

    /** Provides a visible type for exending ResolveListAdapter - fortunately the key
        methods one would need to override in ResolveListAdapter are all public or protected */
    public class ProxyListAdapter extends ResolveListAdapter {
        public ProxyListAdapter(
                Context context, List<Intent> payloadIntents, Intent[] initialIntents,
                List<ResolveInfo> rList, int launchedFromUid, boolean filterLastUsed) {
            super(context, payloadIntents, initialIntents, rList, launchedFromUid, filterLastUsed);
        }

        /** complements getDisplayInfoCount and getDisplayInfoAt */
        public TargetInfo removeDisplayInfoAt(int index) {
            if (index >= 0 && index < mDisplayList.size()) {
                return mDisplayList.remove(index);
            } else {
                return null;
            }
        }
    }
}