Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 019a784c authored by Sudheer Shanka's avatar Sudheer Shanka Committed by android-build-merger
Browse files

Merge "Show admin support dialog if app is suspended." into nyc-dev

am: b5a4d960

* commit 'b5a4d960':
  Show admin support dialog if app is suspended.
parents 12063535 b5a4d960
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.app.admin;

import android.content.Intent;
import android.os.UserHandle;

import java.util.List;
@@ -80,4 +81,15 @@ public abstract class DevicePolicyManagerInternal {
     * @return true if package has a device or profile owner, false otherwise.
     */
    public abstract boolean hasDeviceOwnerOrProfileOwner(String packageName, int userId);

    /**
     * Creates an intent to show the admin support dialog to let the user know that the package is
     * suspended by the admin. This assumes that {@param packageName} is suspended by the
     * device/profile owner. The caller should check if the package is suspended or not.
     *
     * @param packageName The package that is suspended
     * @param userId The user having the suspended package.
     * @return The intent to trigger the admin support dialog.
     */
    public abstract Intent createPackageSuspendedDialogIntent(String packageName, int userId);
}
+1 −42
Original line number Diff line number Diff line
@@ -42,15 +42,13 @@ import com.android.internal.R;

/**
 * A dialog shown to the user when they try to launch an app from a quiet profile
 * ({@link UserManager#isQuietModeEnabled(UserHandle)}, or when the app is suspended by the
 * profile owner or device owner.
 * ({@link UserManager#isQuietModeEnabled(UserHandle)}.
 */
public class UnlaunchableAppActivity extends Activity
        implements DialogInterface.OnDismissListener, DialogInterface.OnClickListener {
    private static final String TAG = "UnlaunchableAppActivity";

    private static final int UNLAUNCHABLE_REASON_QUIET_MODE = 1;
    private static final int UNLAUNCHABLE_REASON_SUSPENDED_PACKAGE = 2;
    private static final String EXTRA_UNLAUNCHABLE_REASON = "unlaunchable_reason";

    private int mUserId;
@@ -74,37 +72,6 @@ public class UnlaunchableAppActivity extends Activity
        if (mReason == UNLAUNCHABLE_REASON_QUIET_MODE) {
            dialogTitle = getResources().getString(R.string.work_mode_off_title);
            dialogMessage = getResources().getString(R.string.work_mode_off_message);
        } else if (mReason == UNLAUNCHABLE_REASON_SUSPENDED_PACKAGE) {
            DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(
                    Context.DEVICE_POLICY_SERVICE);
            String packageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME);
            String packageLabel = packageName;
            try {
                Context userContext = createPackageContextAsUser(packageName, 0,
                        UserHandle.of(mUserId));
                ApplicationInfo appInfo = userContext.getApplicationInfo();
                if (appInfo != null) {
                    packageLabel = userContext.getPackageManager().getApplicationLabel(appInfo)
                            .toString();
                }
            } catch (NameNotFoundException e) {
            }
            dialogTitle = String.format(getResources().getString(R.string.suspended_package_title),
                    packageLabel);
            ComponentName profileOwner = dpm.getProfileOwnerAsUser(mUserId);
            String profileOwnerName = null;
            if (profileOwner != null) {
                dialogMessage = dpm.getShortSupportMessageForUser(profileOwner, mUserId);
                profileOwnerName = dpm.getProfileOwnerNameAsUser(mUserId);
            }
            // Fall back to standard message if profile owner hasn't set something specific.
            if (TextUtils.isEmpty(dialogMessage)) {
                if (TextUtils.isEmpty(profileOwnerName)) {
                    profileOwnerName = getResources().getString(R.string.unknownName);
                }
                dialogMessage = getResources().getString(R.string.suspended_package_message,
                        profileOwnerName);
            }
        } else {
            Log.wtf(TAG, "Invalid unlaunchable type: " + mReason);
            finish();
@@ -154,12 +121,4 @@ public class UnlaunchableAppActivity extends Activity
        intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
        return intent;
    }

    public static Intent createPackageSuspendedDialogIntent(String packageName, int userId) {
        Intent intent = createBaseIntent();
        intent.putExtra(EXTRA_UNLAUNCHABLE_REASON, UNLAUNCHABLE_REASON_SUSPENDED_PACKAGE);
        intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
        intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName);
        return intent;
    }
}
+0 −4
Original line number Diff line number Diff line
@@ -4188,10 +4188,6 @@
    <string name="work_mode_off_message">Allow work profile to function, including apps, background sync, and related features.</string>
    <!-- Title for button to turn on work profile. [CHAR LIMIT=NONE] -->
    <string name="work_mode_turn_on">Turn on</string>
    <!-- Title for dialog displayed when a packge is suspended by device admin. [CHAR LIMIT=30] -->
    <string name="suspended_package_title">%1$s disabled</string>
    <!-- Message for dialog displayed when a packge is suspended by device admin. [CHAR LIMIT=NONE] -->
    <string name="suspended_package_message">Disabled by %1$s administrator. Contact them to learn more.</string>

    <!-- Notification title shown when new SMS/MMS is received while the device is locked [CHAR LIMIT=NONE] -->
    <string name="new_sms_notification_title">You have new messages</string>
+0 −2
Original line number Diff line number Diff line
@@ -2508,8 +2508,6 @@
  <java-symbol type="string" name="work_mode_off_title" />
  <java-symbol type="string" name="work_mode_off_message" />
  <java-symbol type="string" name="work_mode_turn_on" />
  <java-symbol type="string" name="suspended_package_title" />
  <java-symbol type="string" name="suspended_package_message" />

  <!-- New SMS notification while phone is locked. -->
  <java-symbol type="string" name="new_sms_notification_title" />
+7 −10
Original line number Diff line number Diff line
@@ -210,6 +210,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
    private final UserManager mUserManager;
    private final AppOpsManager mAppOpsManager;
    private final KeyguardManager mKeyguardManager;
    private final DevicePolicyManagerInternal mDevicePolicyManagerInternal;

    private final SecurityPolicy mSecurityPolicy;

@@ -232,6 +233,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
        mKeyguardManager = (KeyguardManager) mContext.getSystemService(KEYGUARD_SERVICE);
        mDevicePolicyManagerInternal = LocalServices.getService(DevicePolicyManagerInternal.class);
        mSaveStateHandler = BackgroundThread.getHandler();
        mCallbackHandler = new CallbackHandler(mContext.getMainLooper());
        mBackupRestoreController = new BackupRestoreController();
@@ -298,11 +300,9 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
    }

    private void registerOnCrossProfileProvidersChangedListener() {
        DevicePolicyManagerInternal devicePolicyManager = LocalServices.getService(
                DevicePolicyManagerInternal.class);
        // The device policy is an optional component.
        if (devicePolicyManager != null) {
            devicePolicyManager.addOnCrossProfileWidgetProvidersChangeListener(this);
        if (mDevicePolicyManagerInternal != null) {
            mDevicePolicyManagerInternal.addOnCrossProfileWidgetProvidersChangeListener(this);
        }
    }

@@ -588,7 +588,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
            try {
                UserInfo userInfo = mUserManager.getUserInfo(providerUserId);
                showBadge = userInfo.isManagedProfile();
                onClickIntent = UnlaunchableAppActivity.createPackageSuspendedDialogIntent(
                onClickIntent = mDevicePolicyManagerInternal.createPackageSuspendedDialogIntent(
                        providerPackage, providerUserId);
            } finally {
                Binder.restoreCallingIdentity(identity);
@@ -3574,15 +3574,12 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
        }

        public boolean isProviderWhiteListed(String packageName, int profileId) {
            DevicePolicyManagerInternal devicePolicyManager = LocalServices.getService(
                    DevicePolicyManagerInternal.class);

            // If the policy manager is not available on the device we deny it all.
            if (devicePolicyManager == null) {
            if (mDevicePolicyManagerInternal == null) {
                return false;
            }

            List<String> crossProfilePackages = devicePolicyManager
            List<String> crossProfilePackages = mDevicePolicyManagerInternal
                    .getCrossProfileWidgetProviders(profileId);

            return crossProfilePackages.contains(packageName);
Loading