Merge "Changes to installed app details screen for instant apps"
This commit is contained in:
committed by
Android (Google) Code Review
commit
f85ebb24bb
70
src/com/android/settings/applications/AppStoreUtil.java
Normal file
70
src/com/android/settings/applications/AppStoreUtil.java
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source 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.settings.applications;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
// This class provides methods that help dealing with app stores.
|
||||
public class AppStoreUtil {
|
||||
private static final String LOG_TAG = "AppStoreUtil";
|
||||
|
||||
private static Intent resolveIntent(Context context, Intent i) {
|
||||
ResolveInfo result = context.getPackageManager().resolveActivity(i, 0);
|
||||
return result != null ? new Intent(i.getAction())
|
||||
.setClassName(result.activityInfo.packageName, result.activityInfo.name) : null;
|
||||
}
|
||||
|
||||
// Returns the package name of the app which installed a given packageName, if one is
|
||||
// available.
|
||||
public static String getInstallerPackageName(Context context, String packageName) {
|
||||
String installerPackageName = null;
|
||||
try {
|
||||
installerPackageName =
|
||||
context.getPackageManager().getInstallerPackageName(packageName);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e(LOG_TAG, "Exception while retrieving the package installer of " + packageName, e);
|
||||
}
|
||||
if (installerPackageName == null) {
|
||||
return null;
|
||||
}
|
||||
return installerPackageName;
|
||||
}
|
||||
|
||||
// Returns a link to the installer app store for a given package name.
|
||||
public static Intent getAppStoreLink(Context context, String installerPackageName,
|
||||
String packageName) {
|
||||
Intent intent = new Intent(Intent.ACTION_SHOW_APP_INFO)
|
||||
.setPackage(installerPackageName);
|
||||
final Intent result = resolveIntent(context, intent);
|
||||
if (result != null) {
|
||||
result.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName);
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Convenience method that looks up the installerPackageName for you.
|
||||
public static Intent getAppStoreLink(Context context, String packageName) {
|
||||
String installerPackageName = getInstallerPackageName(context, packageName);
|
||||
return getAppStoreLink(context, installerPackageName, packageName);
|
||||
}
|
||||
}
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import com.android.settings.applications.instantapps.InstantAppButtonsController;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
@@ -29,6 +31,14 @@ public interface ApplicationFeatureProvider {
|
||||
*/
|
||||
AppHeaderController newAppHeaderController(Fragment fragment, View appHeader);
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns a new {@link InstantAppButtonsController} instance for showing buttons
|
||||
* only relevant to instant apps.
|
||||
*/
|
||||
InstantAppButtonsController newInstantAppButtonsController(Fragment fragment,
|
||||
View view);
|
||||
|
||||
/**
|
||||
* Calculates the total number of apps installed on the device via policy across all users
|
||||
* and managed profiles.
|
||||
|
@@ -29,6 +29,7 @@ import android.os.UserManager;
|
||||
import android.util.ArraySet;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.applications.instantapps.InstantAppButtonsController;
|
||||
import com.android.settings.enterprise.DevicePolicyManagerWrapper;
|
||||
|
||||
import java.util.List;
|
||||
@@ -56,6 +57,12 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
||||
return new AppHeaderController(mContext, fragment, appHeader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstantAppButtonsController newInstantAppButtonsController(Fragment fragment,
|
||||
View view) {
|
||||
return new InstantAppButtonsController(mContext, fragment, view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback) {
|
||||
final AllUserPolicyInstalledAppCounter counter =
|
||||
|
@@ -146,6 +146,7 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
private static final int DLG_SPECIAL_DISABLE = DLG_BASE + 3;
|
||||
|
||||
private static final String KEY_HEADER = "header_view";
|
||||
private static final String KEY_INSTANT_APP_BUTTONS = "instant_app_buttons";
|
||||
private static final String KEY_ACTION_BUTTONS = "action_buttons";
|
||||
private static final String KEY_NOTIFICATION = "notification_settings";
|
||||
private static final String KEY_STORAGE = "storage_settings";
|
||||
@@ -222,13 +223,7 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
if (isBundled) {
|
||||
enabled = handleDisableable(mUninstallButton);
|
||||
} else {
|
||||
if ((mPackageInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0
|
||||
&& mUserManager.getUsers().size() >= 2) {
|
||||
// When we have multiple users, there is a separate menu
|
||||
// to uninstall for all users.
|
||||
enabled = false;
|
||||
}
|
||||
mUninstallButton.setText(R.string.uninstall_text);
|
||||
enabled = initUnintsallButtonForUserApp();
|
||||
}
|
||||
// If this is a device admin, it can't be uninstalled or disabled.
|
||||
// We do this here so the text of the button is still set correctly.
|
||||
@@ -298,6 +293,22 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean initUnintsallButtonForUserApp() {
|
||||
boolean enabled = true;
|
||||
if ((mPackageInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0
|
||||
&& mUserManager.getUsers().size() >= 2) {
|
||||
// When we have multiple users, there is a separate menu
|
||||
// to uninstall for all users.
|
||||
enabled = false;
|
||||
} else if (AppUtils.isInstant(mPackageInfo.applicationInfo)) {
|
||||
enabled = false;
|
||||
mUninstallButton.setVisibility(View.GONE);
|
||||
}
|
||||
mUninstallButton.setText(R.string.uninstall_text);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/** Returns if the supplied package is device owner or profile owner of at least one user */
|
||||
private boolean isProfileOrDeviceOwner(String packageName) {
|
||||
List<UserInfo> userInfos = mUserManager.getUsers();
|
||||
@@ -455,12 +466,6 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
mForceStopButton.setEnabled(false);
|
||||
}
|
||||
|
||||
private Intent resolveIntent(Intent i) {
|
||||
ResolveInfo result = getContext().getPackageManager().resolveActivity(i, 0);
|
||||
return result != null ? new Intent(i.getAction())
|
||||
.setClassName(result.activityInfo.packageName, result.activityInfo.name) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.add(0, UNINSTALL_UPDATES, 0, R.string.app_factory_reset)
|
||||
@@ -570,6 +575,8 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
} else if (PackageUtil.countPackageInUsers(mPm, mUserManager, mPackageName) < 2
|
||||
&& (appEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) != 0) {
|
||||
showIt = false;
|
||||
} else if (AppUtils.isInstant(appEntry.info)) {
|
||||
showIt = false;
|
||||
}
|
||||
return showIt;
|
||||
}
|
||||
@@ -800,11 +807,15 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
}
|
||||
}
|
||||
|
||||
private void checkForceStop() {
|
||||
@VisibleForTesting
|
||||
void checkForceStop() {
|
||||
if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
|
||||
// User can't force stop device admin.
|
||||
Log.w(LOG_TAG, "User can't force stop device admin");
|
||||
updateForceStopButton(false);
|
||||
} else if (AppUtils.isInstant(mPackageInfo.applicationInfo)) {
|
||||
updateForceStopButton(false);
|
||||
mForceStopButton.setVisibility(View.GONE);
|
||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_STOPPED) == 0) {
|
||||
// If the app isn't explicitly stopped, then always show the
|
||||
// force stop button.
|
||||
@@ -1064,6 +1075,7 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
}
|
||||
|
||||
addAppInstallerInfoPref(screen);
|
||||
maybeAddInstantAppButtons();
|
||||
}
|
||||
|
||||
private boolean isPotentialAppSource() {
|
||||
@@ -1074,16 +1086,9 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
}
|
||||
|
||||
private void addAppInstallerInfoPref(PreferenceScreen screen) {
|
||||
String installerPackageName = null;
|
||||
try {
|
||||
installerPackageName =
|
||||
getContext().getPackageManager().getInstallerPackageName(mPackageName);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e(TAG, "Exception while retrieving the package installer of " + mPackageName, e);
|
||||
}
|
||||
if (installerPackageName == null) {
|
||||
return;
|
||||
}
|
||||
String installerPackageName =
|
||||
AppStoreUtil.getInstallerPackageName(getContext(), mPackageName);
|
||||
|
||||
final CharSequence installerLabel = Utils.getApplicationLabel(getContext(),
|
||||
installerPackageName);
|
||||
if (installerLabel == null) {
|
||||
@@ -1096,18 +1101,31 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
pref.setTitle(R.string.app_install_details_title);
|
||||
pref.setKey("app_info_store");
|
||||
pref.setSummary(getString(R.string.app_install_details_summary, installerLabel));
|
||||
final Intent intent = new Intent(Intent.ACTION_SHOW_APP_INFO)
|
||||
.setPackage(installerPackageName);
|
||||
final Intent result = resolveIntent(intent);
|
||||
if (result != null) {
|
||||
result.putExtra(Intent.EXTRA_PACKAGE_NAME, mPackageName);
|
||||
pref.setIntent(result);
|
||||
|
||||
Intent intent =
|
||||
AppStoreUtil.getAppStoreLink(getContext(), installerPackageName, mPackageName);
|
||||
if (intent != null) {
|
||||
pref.setIntent(intent);
|
||||
} else {
|
||||
pref.setEnabled(false);
|
||||
}
|
||||
category.addPreference(pref);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void maybeAddInstantAppButtons() {
|
||||
if (AppUtils.isInstant(mPackageInfo.applicationInfo)) {
|
||||
LayoutPreference buttons = (LayoutPreference) findPreference(KEY_INSTANT_APP_BUTTONS);
|
||||
final Activity activity = getActivity();
|
||||
FeatureFactory.getFactory(activity)
|
||||
.getApplicationFeatureProvider(activity)
|
||||
.newInstantAppButtonsController(this,
|
||||
buttons.findViewById(R.id.instant_app_button_container))
|
||||
.setPackageName(mPackageName)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasPermission(String permission) {
|
||||
if (mPackageInfo == null || mPackageInfo.requestedPermissions == null) {
|
||||
return false;
|
||||
|
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source 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.settings.applications.instantapps;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.AppStoreUtil;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
|
||||
/** Encapsulates a container for buttons relevant to instant apps */
|
||||
public class InstantAppButtonsController {
|
||||
|
||||
private final Context mContext;
|
||||
private final Fragment mFragment;
|
||||
private final View mView;
|
||||
private String mPackageName;
|
||||
|
||||
public InstantAppButtonsController(Context context, Fragment fragment, View view) {
|
||||
mContext = context;
|
||||
mFragment = fragment;
|
||||
mView = view;
|
||||
}
|
||||
|
||||
public InstantAppButtonsController setPackageName(String packageName) {
|
||||
mPackageName = packageName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void bindButtons() {
|
||||
Button installButton = (Button)mView.findViewById(R.id.install);
|
||||
Button clearDataButton = (Button)mView.findViewById(R.id.clear_data);
|
||||
Intent installIntent = AppStoreUtil.getAppStoreLink(mContext, mPackageName);
|
||||
if (installIntent != null) {
|
||||
installButton.setEnabled(true);
|
||||
installButton.setOnClickListener(v -> mFragment.startActivity(installIntent));
|
||||
}
|
||||
clearDataButton.setOnClickListener(v -> {
|
||||
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider().action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_CLEAR_INSTANT_APP, mPackageName);
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
pm.clearApplicationUserData(mPackageName, null);
|
||||
});
|
||||
}
|
||||
|
||||
public InstantAppButtonsController show() {
|
||||
bindButtons();
|
||||
mView.setVisibility(View.VISIBLE);
|
||||
return this;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user