Loading res/layout/instant_app_buttons.xml +27 −12 Original line number Diff line number Diff line Loading @@ -20,24 +20,39 @@ android:id="@+id/instant_app_button_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="4dp" android:paddingStart="8dp" android:paddingEnd="8dp" android:visibility="gone"> android:gravity="center" android:paddingTop="24dp" android:paddingStart="68dp" android:paddingEnd="24dp" android:orientation="horizontal"> <FrameLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"> <Button android:id="@+id/install" style="@style/ActionPrimaryButton" android:enabled="false" android:layout_width="0dp" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="4dp" android:text="@string/install_text"/> <Button android:id="@+id/launch" style="@style/ActionPrimaryButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="4dp" android:text="@string/launch_instant_app"/> </FrameLayout> <Space android:layout_width="16dp" android:layout_height="wrap_content" /> <Button android:id="@+id/clear_data" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="4dp" android:text="@string/clear_instant_app_data"/> </LinearLayout> src/com/android/settings/applications/ApplicationFeatureProvider.java +0 −11 Original line number Diff line number Diff line Loading @@ -17,24 +17,13 @@ package com.android.settings.applications; import android.annotation.UserIdInt; import android.app.Fragment; import android.content.Intent; import android.view.View; import com.android.settings.applications.instantapps.InstantAppButtonsController; import java.util.List; import java.util.Set; public interface ApplicationFeatureProvider { /** * Returns a new {@link InstantAppButtonsController} instance for showing buttons * only relevant to instant apps. */ InstantAppButtonsController newInstantAppButtonsController(Fragment fragment, View view, InstantAppButtonsController.ShowDialogDelegate showDialogDelegate); /** * Calculates the total number of apps installed on the device via policy in the current user * and all its managed profiles. Loading src/com/android/settings/applications/ApplicationFeatureProviderImpl.java +0 −9 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.settings.applications; import android.app.Fragment; import android.content.Context; import android.content.Intent; import android.content.pm.ComponentInfo; Loading @@ -26,9 +25,7 @@ import android.content.pm.UserInfo; import android.os.RemoteException; import android.os.UserManager; import android.util.ArraySet; import android.view.View; import com.android.settings.applications.instantapps.InstantAppButtonsController; import com.android.settings.wrapper.DevicePolicyManagerWrapper; import com.android.settings.wrapper.IPackageManagerWrapper; import com.android.settingslib.wrapper.PackageManagerWrapper; Loading @@ -54,12 +51,6 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide mUm = UserManager.get(mContext); } @Override public InstantAppButtonsController newInstantAppButtonsController(Fragment fragment, View view, InstantAppButtonsController.ShowDialogDelegate showDialogDelegate) { return new InstantAppButtonsController(mContext, fragment, view, showDialogDelegate); } @Override public void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback) { final CurrentUserAndManagedProfilePolicyInstalledAppCounter counter = Loading src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java +3 −1 Original line number Diff line number Diff line Loading @@ -86,6 +86,7 @@ public class AppInfoDashboardFragment extends DashboardFragment @VisibleForTesting static final int UNINSTALL_ALL_USERS_MENU = 1; @VisibleForTesting static final int UNINSTALL_UPDATES = 2; static final int FORCE_STOP_MENU = 3; static final int INSTALL_INSTANT_APP_MENU = 4; // Result code identifiers @VisibleForTesting Loading @@ -103,6 +104,7 @@ public class AppInfoDashboardFragment extends DashboardFragment static final int DLG_FORCE_STOP = DLG_BASE + 1; private static final int DLG_DISABLE = DLG_BASE + 2; private static final int DLG_SPECIAL_DISABLE = DLG_BASE + 3; static final int DLG_CLEAR_INSTANT_APP = DLG_BASE + 4; private static final String KEY_ADVANCED_APP_INFO_CATEGORY = "advanced_app_info"; Loading Loading @@ -244,7 +246,7 @@ public class AppInfoDashboardFragment extends DashboardFragment // The following are controllers for preferences that don't need to refresh the preference // state when app state changes. mInstantAppButtonPreferenceController = new InstantAppButtonsPreferenceController(context, this, packageName); new InstantAppButtonsPreferenceController(context, this, packageName, lifecycle); controllers.add(mInstantAppButtonPreferenceController); controllers.add(new AppBatteryPreferenceController(context, this, packageName, lifecycle)); controllers.add(new AppMemoryPreferenceController(context, this, lifecycle)); Loading src/com/android/settings/applications/appinfo/InstantAppButtonsPreferenceController.java +126 −18 Original line number Diff line number Diff line Loading @@ -18,30 +18,62 @@ package com.android.settings.applications.appinfo; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Bundle; import android.os.UserHandle; import android.support.annotation.VisibleForTesting; import android.support.v7.preference.PreferenceScreen; import android.text.TextUtils; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.Button; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.applications.ApplicationFeatureProvider; import com.android.settings.applications.AppStoreUtil; import com.android.settings.applications.LayoutPreference; import com.android.settings.applications.instantapps.InstantAppButtonsController; import com.android.settings.core.BasePreferenceController; import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.applications.AppUtils; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnCreateOptionsMenu; import com.android.settingslib.core.lifecycle.events.OnOptionsItemSelected; import com.android.settingslib.core.lifecycle.events.OnPrepareOptionsMenu; import com.android.settingslib.wrapper.PackageManagerWrapper; public class InstantAppButtonsPreferenceController extends BasePreferenceController { import java.util.List; public class InstantAppButtonsPreferenceController extends BasePreferenceController implements LifecycleObserver, OnCreateOptionsMenu, OnPrepareOptionsMenu, OnOptionsItemSelected, DialogInterface.OnClickListener { private static final String KEY_INSTANT_APP_BUTTONS = "instant_app_buttons"; private static final String META_DATA_DEFAULT_URI = "default-url"; private final AppInfoDashboardFragment mParent; private final String mPackageName; private InstantAppButtonsController mInstantAppButtonsController; private final PackageManagerWrapper mPackageManagerWrapper; private String mLaunchUri; private LayoutPreference mPreference; private MenuItem mInstallMenu; public InstantAppButtonsPreferenceController(Context context, AppInfoDashboardFragment parent, String packageName) { String packageName, Lifecycle lifecycle) { super(context, KEY_INSTANT_APP_BUTTONS); mParent = parent; mPackageName = packageName; mPackageManagerWrapper = new PackageManagerWrapper(context.getPackageManager()); mLaunchUri = getDefaultLaunchUri(); if (lifecycle != null) { lifecycle.addObserver(this); } } @Override Loading @@ -53,22 +85,98 @@ public class InstantAppButtonsPreferenceController extends BasePreferenceControl @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); LayoutPreference buttons = (LayoutPreference) screen.findPreference(KEY_INSTANT_APP_BUTTONS); mInstantAppButtonsController = getApplicationFeatureProvider() .newInstantAppButtonsController(mParent, buttons.findViewById(R.id.instant_app_button_container), id -> mParent.showDialogInner(id, 0)) .setPackageName(mPackageName) .show(); mPreference = (LayoutPreference) screen.findPreference(KEY_INSTANT_APP_BUTTONS); initButtons(mPreference.findViewById(R.id.instant_app_button_container)); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if (!TextUtils.isEmpty(mLaunchUri)) { menu.add(0, AppInfoDashboardFragment.INSTALL_INSTANT_APP_MENU, 2, R.string.install_text) .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } } @Override public boolean onOptionsItemSelected(MenuItem menuItem) { if (menuItem.getItemId() == AppInfoDashboardFragment.INSTALL_INSTANT_APP_MENU) { final Intent appStoreIntent = AppStoreUtil.getAppStoreLink(mContext, mPackageName); if (appStoreIntent != null) { mParent.startActivity(appStoreIntent); } return true; } return false; } @Override public void onPrepareOptionsMenu(Menu menu) { mInstallMenu = menu.findItem(AppInfoDashboardFragment.INSTALL_INSTANT_APP_MENU); final Intent appStoreIntent = AppStoreUtil.getAppStoreLink(mContext, mPackageName); if (appStoreIntent == null) { mInstallMenu.setEnabled(false); } } public AlertDialog createDialog(int id) { return mInstantAppButtonsController.createDialog(id); @Override public void onClick(DialogInterface dialog, int which) { FeatureFactory.getFactory(mContext).getMetricsFeatureProvider() .action(mContext, MetricsEvent.ACTION_SETTINGS_CLEAR_INSTANT_APP, mPackageName); mPackageManagerWrapper.deletePackageAsUser( mPackageName, null, 0, UserHandle.myUserId()); } @VisibleForTesting ApplicationFeatureProvider getApplicationFeatureProvider() { return FeatureFactory.getFactory(mContext).getApplicationFeatureProvider(mContext); AlertDialog createDialog(int id) { if (id == AppInfoDashboardFragment.DLG_CLEAR_INSTANT_APP) { AlertDialog confirmDialog = new AlertDialog.Builder(mContext) .setPositiveButton(R.string.clear_instant_app_data, this) .setNegativeButton(R.string.cancel, null) .setTitle(R.string.clear_instant_app_data) .setMessage(mContext.getString(R.string.clear_instant_app_confirmation)) .create(); return confirmDialog; } return null; } private void initButtons(View view) { final Button installButton = view.findViewById(R.id.install); final Button clearDataButton = view.findViewById(R.id.clear_data); final Button launchButton = view.findViewById(R.id.launch); if (!TextUtils.isEmpty(mLaunchUri)) { installButton.setVisibility(View.GONE); final Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(mLaunchUri)); launchButton.setOnClickListener(v -> mParent.startActivity(intent)); } else { launchButton.setVisibility(View.GONE); final Intent appStoreIntent = AppStoreUtil.getAppStoreLink(mContext, mPackageName); if (appStoreIntent != null) { installButton.setOnClickListener(v -> mParent.startActivity(appStoreIntent)); } else { installButton.setEnabled(false); } } clearDataButton.setOnClickListener( v -> mParent.showDialogInner(mParent.DLG_CLEAR_INSTANT_APP, 0)); } private String getDefaultLaunchUri() { final PackageManager manager = mContext.getPackageManager(); final Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setPackage(mPackageName); final List<ResolveInfo> infos = manager.queryIntentActivities( intent, PackageManager.GET_META_DATA | PackageManager.MATCH_INSTANT); for (ResolveInfo info : infos) { final Bundle metaData = info.activityInfo.metaData; if (metaData != null) { final String launchUri = metaData.getString(META_DATA_DEFAULT_URI); if (!TextUtils.isEmpty(launchUri)) { return launchUri; } } } return null; } } Loading
res/layout/instant_app_buttons.xml +27 −12 Original line number Diff line number Diff line Loading @@ -20,24 +20,39 @@ android:id="@+id/instant_app_button_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="4dp" android:paddingStart="8dp" android:paddingEnd="8dp" android:visibility="gone"> android:gravity="center" android:paddingTop="24dp" android:paddingStart="68dp" android:paddingEnd="24dp" android:orientation="horizontal"> <FrameLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"> <Button android:id="@+id/install" style="@style/ActionPrimaryButton" android:enabled="false" android:layout_width="0dp" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="4dp" android:text="@string/install_text"/> <Button android:id="@+id/launch" style="@style/ActionPrimaryButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="4dp" android:text="@string/launch_instant_app"/> </FrameLayout> <Space android:layout_width="16dp" android:layout_height="wrap_content" /> <Button android:id="@+id/clear_data" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="4dp" android:text="@string/clear_instant_app_data"/> </LinearLayout>
src/com/android/settings/applications/ApplicationFeatureProvider.java +0 −11 Original line number Diff line number Diff line Loading @@ -17,24 +17,13 @@ package com.android.settings.applications; import android.annotation.UserIdInt; import android.app.Fragment; import android.content.Intent; import android.view.View; import com.android.settings.applications.instantapps.InstantAppButtonsController; import java.util.List; import java.util.Set; public interface ApplicationFeatureProvider { /** * Returns a new {@link InstantAppButtonsController} instance for showing buttons * only relevant to instant apps. */ InstantAppButtonsController newInstantAppButtonsController(Fragment fragment, View view, InstantAppButtonsController.ShowDialogDelegate showDialogDelegate); /** * Calculates the total number of apps installed on the device via policy in the current user * and all its managed profiles. Loading
src/com/android/settings/applications/ApplicationFeatureProviderImpl.java +0 −9 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.settings.applications; import android.app.Fragment; import android.content.Context; import android.content.Intent; import android.content.pm.ComponentInfo; Loading @@ -26,9 +25,7 @@ import android.content.pm.UserInfo; import android.os.RemoteException; import android.os.UserManager; import android.util.ArraySet; import android.view.View; import com.android.settings.applications.instantapps.InstantAppButtonsController; import com.android.settings.wrapper.DevicePolicyManagerWrapper; import com.android.settings.wrapper.IPackageManagerWrapper; import com.android.settingslib.wrapper.PackageManagerWrapper; Loading @@ -54,12 +51,6 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide mUm = UserManager.get(mContext); } @Override public InstantAppButtonsController newInstantAppButtonsController(Fragment fragment, View view, InstantAppButtonsController.ShowDialogDelegate showDialogDelegate) { return new InstantAppButtonsController(mContext, fragment, view, showDialogDelegate); } @Override public void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback) { final CurrentUserAndManagedProfilePolicyInstalledAppCounter counter = Loading
src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java +3 −1 Original line number Diff line number Diff line Loading @@ -86,6 +86,7 @@ public class AppInfoDashboardFragment extends DashboardFragment @VisibleForTesting static final int UNINSTALL_ALL_USERS_MENU = 1; @VisibleForTesting static final int UNINSTALL_UPDATES = 2; static final int FORCE_STOP_MENU = 3; static final int INSTALL_INSTANT_APP_MENU = 4; // Result code identifiers @VisibleForTesting Loading @@ -103,6 +104,7 @@ public class AppInfoDashboardFragment extends DashboardFragment static final int DLG_FORCE_STOP = DLG_BASE + 1; private static final int DLG_DISABLE = DLG_BASE + 2; private static final int DLG_SPECIAL_DISABLE = DLG_BASE + 3; static final int DLG_CLEAR_INSTANT_APP = DLG_BASE + 4; private static final String KEY_ADVANCED_APP_INFO_CATEGORY = "advanced_app_info"; Loading Loading @@ -244,7 +246,7 @@ public class AppInfoDashboardFragment extends DashboardFragment // The following are controllers for preferences that don't need to refresh the preference // state when app state changes. mInstantAppButtonPreferenceController = new InstantAppButtonsPreferenceController(context, this, packageName); new InstantAppButtonsPreferenceController(context, this, packageName, lifecycle); controllers.add(mInstantAppButtonPreferenceController); controllers.add(new AppBatteryPreferenceController(context, this, packageName, lifecycle)); controllers.add(new AppMemoryPreferenceController(context, this, lifecycle)); Loading
src/com/android/settings/applications/appinfo/InstantAppButtonsPreferenceController.java +126 −18 Original line number Diff line number Diff line Loading @@ -18,30 +18,62 @@ package com.android.settings.applications.appinfo; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Bundle; import android.os.UserHandle; import android.support.annotation.VisibleForTesting; import android.support.v7.preference.PreferenceScreen; import android.text.TextUtils; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.Button; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.applications.ApplicationFeatureProvider; import com.android.settings.applications.AppStoreUtil; import com.android.settings.applications.LayoutPreference; import com.android.settings.applications.instantapps.InstantAppButtonsController; import com.android.settings.core.BasePreferenceController; import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.applications.AppUtils; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnCreateOptionsMenu; import com.android.settingslib.core.lifecycle.events.OnOptionsItemSelected; import com.android.settingslib.core.lifecycle.events.OnPrepareOptionsMenu; import com.android.settingslib.wrapper.PackageManagerWrapper; public class InstantAppButtonsPreferenceController extends BasePreferenceController { import java.util.List; public class InstantAppButtonsPreferenceController extends BasePreferenceController implements LifecycleObserver, OnCreateOptionsMenu, OnPrepareOptionsMenu, OnOptionsItemSelected, DialogInterface.OnClickListener { private static final String KEY_INSTANT_APP_BUTTONS = "instant_app_buttons"; private static final String META_DATA_DEFAULT_URI = "default-url"; private final AppInfoDashboardFragment mParent; private final String mPackageName; private InstantAppButtonsController mInstantAppButtonsController; private final PackageManagerWrapper mPackageManagerWrapper; private String mLaunchUri; private LayoutPreference mPreference; private MenuItem mInstallMenu; public InstantAppButtonsPreferenceController(Context context, AppInfoDashboardFragment parent, String packageName) { String packageName, Lifecycle lifecycle) { super(context, KEY_INSTANT_APP_BUTTONS); mParent = parent; mPackageName = packageName; mPackageManagerWrapper = new PackageManagerWrapper(context.getPackageManager()); mLaunchUri = getDefaultLaunchUri(); if (lifecycle != null) { lifecycle.addObserver(this); } } @Override Loading @@ -53,22 +85,98 @@ public class InstantAppButtonsPreferenceController extends BasePreferenceControl @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); LayoutPreference buttons = (LayoutPreference) screen.findPreference(KEY_INSTANT_APP_BUTTONS); mInstantAppButtonsController = getApplicationFeatureProvider() .newInstantAppButtonsController(mParent, buttons.findViewById(R.id.instant_app_button_container), id -> mParent.showDialogInner(id, 0)) .setPackageName(mPackageName) .show(); mPreference = (LayoutPreference) screen.findPreference(KEY_INSTANT_APP_BUTTONS); initButtons(mPreference.findViewById(R.id.instant_app_button_container)); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if (!TextUtils.isEmpty(mLaunchUri)) { menu.add(0, AppInfoDashboardFragment.INSTALL_INSTANT_APP_MENU, 2, R.string.install_text) .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } } @Override public boolean onOptionsItemSelected(MenuItem menuItem) { if (menuItem.getItemId() == AppInfoDashboardFragment.INSTALL_INSTANT_APP_MENU) { final Intent appStoreIntent = AppStoreUtil.getAppStoreLink(mContext, mPackageName); if (appStoreIntent != null) { mParent.startActivity(appStoreIntent); } return true; } return false; } @Override public void onPrepareOptionsMenu(Menu menu) { mInstallMenu = menu.findItem(AppInfoDashboardFragment.INSTALL_INSTANT_APP_MENU); final Intent appStoreIntent = AppStoreUtil.getAppStoreLink(mContext, mPackageName); if (appStoreIntent == null) { mInstallMenu.setEnabled(false); } } public AlertDialog createDialog(int id) { return mInstantAppButtonsController.createDialog(id); @Override public void onClick(DialogInterface dialog, int which) { FeatureFactory.getFactory(mContext).getMetricsFeatureProvider() .action(mContext, MetricsEvent.ACTION_SETTINGS_CLEAR_INSTANT_APP, mPackageName); mPackageManagerWrapper.deletePackageAsUser( mPackageName, null, 0, UserHandle.myUserId()); } @VisibleForTesting ApplicationFeatureProvider getApplicationFeatureProvider() { return FeatureFactory.getFactory(mContext).getApplicationFeatureProvider(mContext); AlertDialog createDialog(int id) { if (id == AppInfoDashboardFragment.DLG_CLEAR_INSTANT_APP) { AlertDialog confirmDialog = new AlertDialog.Builder(mContext) .setPositiveButton(R.string.clear_instant_app_data, this) .setNegativeButton(R.string.cancel, null) .setTitle(R.string.clear_instant_app_data) .setMessage(mContext.getString(R.string.clear_instant_app_confirmation)) .create(); return confirmDialog; } return null; } private void initButtons(View view) { final Button installButton = view.findViewById(R.id.install); final Button clearDataButton = view.findViewById(R.id.clear_data); final Button launchButton = view.findViewById(R.id.launch); if (!TextUtils.isEmpty(mLaunchUri)) { installButton.setVisibility(View.GONE); final Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(mLaunchUri)); launchButton.setOnClickListener(v -> mParent.startActivity(intent)); } else { launchButton.setVisibility(View.GONE); final Intent appStoreIntent = AppStoreUtil.getAppStoreLink(mContext, mPackageName); if (appStoreIntent != null) { installButton.setOnClickListener(v -> mParent.startActivity(appStoreIntent)); } else { installButton.setEnabled(false); } } clearDataButton.setOnClickListener( v -> mParent.showDialogInner(mParent.DLG_CLEAR_INSTANT_APP, 0)); } private String getDefaultLaunchUri() { final PackageManager manager = mContext.getPackageManager(); final Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setPackage(mPackageName); final List<ResolveInfo> infos = manager.queryIntentActivities( intent, PackageManager.GET_META_DATA | PackageManager.MATCH_INSTANT); for (ResolveInfo info : infos) { final Bundle metaData = info.activityInfo.metaData; if (metaData != null) { final String launchUri = metaData.getString(META_DATA_DEFAULT_URI); if (!TextUtils.isEmpty(launchUri)) { return launchUri; } } } return null; } }