diff options
author | Wilhelm Fitzpatrick <rafial@cyngn.com> | 2016-05-27 10:54:30 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2016-06-09 14:14:01 -0700 |
commit | eb7ff1a410cbd8851139fd5ea5088ab03a759157 (patch) | |
tree | 13be2e80233e19f1f32f7966613c082b1c9d634d /core | |
parent | e704fc0d3a5bcf8c815c4af58d196e27c6ee47d3 (diff) | |
download | frameworks_base-eb7ff1a410cbd8851139fd5ea5088ab03a759157.zip frameworks_base-eb7ff1a410cbd8851139fd5ea5088ab03a759157.tar.gz frameworks_base-eb7ff1a410cbd8851139fd5ea5088ab03a759157.tar.bz2 |
Framework: allow ResolverActivity to be specialized from other package
PackageManager already has hooks to allow the Disambiguation Dialog aka
ResolverActivity to be substituted at runtime by a custom activity
named via system property. Since the internal ResolverActivity already
has good extension points (for use by ChooserActivity), it is useful
to allow a customized ResolverActivity, provided in a separate package
to be able to extend the internal activity, thus preserving core
behavior as much as possible, and making forward porting easier.
This patch attempts to make as few changes to the core ResolverActivity
as possible to make up stream patching easy, and isolates most of the
needed code into a shim (ResolverProxy) which is mostly concerned with
changing the access modifier of key methods from package-private to
protected. This is necessary to allow overriding of those methods from
a subclass originating from a different class loader.
Change-Id: I17070964fca73f0d11b4fe8d809b2a775ba9e7e6
Diffstat (limited to 'core')
-rw-r--r-- | core/java/com/android/internal/app/ResolverActivity.java | 4 | ||||
-rw-r--r-- | core/java/com/android/internal/app/ResolverProxy.java | 146 |
2 files changed, 148 insertions, 2 deletions
diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index 00e250b..4c3cc4d 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -91,7 +91,7 @@ public class ResolverActivity extends Activity { private ResolveListAdapter mAdapter; private PackageManager mPm; private boolean mSafeForwardingMode; - private boolean mAlwaysUseOption; + /*package*/ boolean mAlwaysUseOption; private AbsListView mAdapterView; private ViewGroup mFilteredItemContainer; private Button mAlwaysButton; @@ -1571,7 +1571,7 @@ public class ResolverActivity extends Activity { return mDisplayList.get(index); } - public final View getView(int position, View convertView, ViewGroup parent) { + public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { view = createView(parent); diff --git a/core/java/com/android/internal/app/ResolverProxy.java b/core/java/com/android/internal/app/ResolverProxy.java new file mode 100644 index 0000000..f59fd11 --- /dev/null +++ b/core/java/com/android/internal/app/ResolverProxy.java @@ -0,0 +1,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; + } + } + } +} |