Merge "Updating strings for activity interceptor dialog" into pi-dev

am: 3e5b5076a2

Change-Id: Ifedcc426f81670c705408f01638c69a761044dff
This commit is contained in:
Suprabh Shukla
2018-04-11 16:54:52 -07:00
committed by android-build-merger
5 changed files with 46 additions and 20 deletions

View File

@@ -19,10 +19,10 @@ package com.android.internal.app;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.UserHandle;
import android.util.Slog;
import android.view.Window;
import android.view.WindowManager;
import com.android.internal.R;
@@ -31,6 +31,10 @@ public class SuspendedAppActivity extends AlertActivity
implements DialogInterface.OnClickListener {
private static final String TAG = "SuspendedAppActivity";
public static final String EXTRA_SUSPENDED_PACKAGE =
"SuspendedAppActivity.extra.SUSPENDED_PACKAGE";
public static final String EXTRA_SUSPENDING_PACKAGE =
"SuspendedAppActivity.extra.SUSPENDING_PACKAGE";
public static final String EXTRA_DIALOG_MESSAGE = "SuspendedAppActivity.extra.DIALOG_MESSAGE";
public static final String EXTRA_MORE_DETAILS_INTENT =
"SuspendedAppActivity.extra.MORE_DETAILS_INTENT";
@@ -38,10 +42,19 @@ public class SuspendedAppActivity extends AlertActivity
private Intent mMoreDetailsIntent;
private int mUserId;
private CharSequence getAppLabel(String packageName) {
final PackageManager pm = getPackageManager();
try {
return pm.getApplicationInfoAsUser(packageName, 0, mUserId).loadLabel(pm);
} catch (PackageManager.NameNotFoundException ne) {
Slog.e(TAG, "Package " + packageName + " not found", ne);
}
return packageName;
}
@Override
public void onCreate(Bundle icicle) {
Window window = getWindow();
window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
super.onCreate(icicle);
final Intent intent = getIntent();
@@ -52,15 +65,22 @@ public class SuspendedAppActivity extends AlertActivity
finish();
return;
}
String dialogMessage = intent.getStringExtra(EXTRA_DIALOG_MESSAGE);
if (dialogMessage == null) {
dialogMessage = getString(R.string.app_suspended_default_message);
final String suppliedMessage = intent.getStringExtra(EXTRA_DIALOG_MESSAGE);
final CharSequence suspendedAppLabel = getAppLabel(
intent.getStringExtra(EXTRA_SUSPENDED_PACKAGE));
final CharSequence dialogMessage;
if (suppliedMessage == null) {
dialogMessage = getString(R.string.app_suspended_default_message,
suspendedAppLabel,
getAppLabel(intent.getStringExtra(EXTRA_SUSPENDING_PACKAGE)));
} else {
dialogMessage = String.format(getResources().getConfiguration().getLocales().get(0),
suppliedMessage, suspendedAppLabel);
}
final AlertController.AlertParams ap = mAlertParams;
ap.mTitle = getString(R.string.app_suspended_title);
ap.mMessage = String.format(getResources().getConfiguration().getLocales().get(0),
dialogMessage, intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME));
ap.mMessage = dialogMessage;
ap.mPositiveButtonText = getString(android.R.string.ok);
if (mMoreDetailsIntent != null) {
ap.mNeutralButtonText = getString(R.string.app_suspended_more_details);

View File

@@ -4704,11 +4704,13 @@
<string name="locale_search_menu">Search</string>
<!-- Title of the dialog that is shown when the user tries to launch a suspended application [CHAR LIMIT=30] -->
<string name="app_suspended_title">Action not allowed</string>
<string name="app_suspended_title">Can\u2019t open app</string>
<!-- Default message shown in the dialog that is shown when the user tries to launch a suspended application [CHAR LIMIT=NONE] -->
<string name="app_suspended_default_message">The application <xliff:g id="app_name" example="GMail">%1$s</xliff:g> is currently disabled.</string>
<string name="app_suspended_default_message">
The app <xliff:g id="app_name" example="Gmail">%1$s</xliff:g> isn\u2019t available right now. This is managed by <xliff:g id="app_name" example="Settings">%2$s</xliff:g>.
</string>
<!-- Title of the button to show users more details about why the app has been suspended [CHAR LIMIT=50]-->
<string name="app_suspended_more_details">More details</string>
<string name="app_suspended_more_details">Learn more</string>
<!-- Title of a dialog. The string is asking if the user wants to turn on their work profile, which contains work apps that are managed by their employer. "Work" is an adjective. [CHAR LIMIT=30] -->
<string name="work_mode_off_title">Turn on work profile?</string>

View File

@@ -234,8 +234,9 @@ class ActivityStartInterceptor {
private Intent createSuspendedAppInterceptIntent(String suspendedPackage,
String suspendingPackage, String dialogMessage, int userId) {
final Intent interceptIntent = new Intent(mServiceContext, SuspendedAppActivity.class)
.putExtra(Intent.EXTRA_PACKAGE_NAME, suspendedPackage)
.putExtra(SuspendedAppActivity.EXTRA_SUSPENDED_PACKAGE, suspendedPackage)
.putExtra(SuspendedAppActivity.EXTRA_DIALOG_MESSAGE, dialogMessage)
.putExtra(SuspendedAppActivity.EXTRA_SUSPENDING_PACKAGE, suspendingPackage)
.putExtra(Intent.EXTRA_USER_ID, userId)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

View File

@@ -32,6 +32,7 @@ import android.content.IntentFilter;
import android.content.pm.IPackageManager;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.BaseBundle;
import android.os.Bundle;
import android.os.Handler;
@@ -68,6 +69,7 @@ import java.util.concurrent.atomic.AtomicReference;
@LargeTest
public class SuspendPackagesTest {
private static final String TAG = SuspendPackagesTest.class.getSimpleName();
private static final String TEST_APP_LABEL = "Suspend Test App";
private static final String TEST_APP_PACKAGE_NAME = SuspendTestReceiver.PACKAGE_NAME;
private static final String[] PACKAGES_TO_SUSPEND = new String[]{TEST_APP_PACKAGE_NAME};
@@ -446,23 +448,24 @@ public class SuspendPackagesTest {
turnScreenOn();
mAppCommsReceiver.register(mReceiverHandler, ACTION_REPORT_MORE_DETAILS_ACTIVITY_STARTED,
ACTION_REPORT_TEST_ACTIVITY_STARTED);
final String testMessage = "This is a test message";
final String testMessage = "This is a test message to report suspension of %1$s";
suspendTestPackage(null, null, testMessage);
startTestAppActivity();
assertNull("No broadcast was expected from app", mAppCommsReceiver.pollForIntent(2));
assertNotNull("Given dialog message not shown",
mUiDevice.wait(Until.findObject(By.text(testMessage)), 5000));
final String buttonText = "More details";
assertNotNull("Given dialog message not shown", mUiDevice.wait(
Until.findObject(By.text(String.format(testMessage, TEST_APP_LABEL))), 5000));
final String buttonText = mContext.getResources().getString(Resources.getSystem()
.getIdentifier("app_suspended_more_details", "string", "android"));
final UiObject2 moreDetailsButton = mUiDevice.findObject(
By.clickable(true).text(buttonText));
assertNotNull("\"More Details\" button not shown", moreDetailsButton);
assertNotNull(buttonText + " button not shown", moreDetailsButton);
moreDetailsButton.click();
final Intent intentFromApp = mAppCommsReceiver.receiveIntentFromApp();
assertEquals("\"More Details\" activity start not reported",
assertEquals(buttonText + " activity start not reported",
ACTION_REPORT_MORE_DETAILS_ACTIVITY_STARTED, intentFromApp.getAction());
final String receivedPackageName = intentFromApp.getStringExtra(
EXTRA_RECEIVED_PACKAGE_NAME);
assertEquals("Wrong package name received by \"More Details\" activity",
assertEquals("Wrong package name received by " + buttonText + " activity",
TEST_APP_PACKAGE_NAME, receivedPackageName);
}

View File

@@ -17,7 +17,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.servicestests.apps.suspendtestapp">
<application>
<application android:label="Suspend Test App">
<activity android:name=".SuspendTestActivity"
android:exported="true" />
<receiver android:name=".SuspendTestReceiver"