Merge "Make SeekBarPreference to be selectable" into qt-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index cb63df9..3118403 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2403,16 +2403,6 @@
android:excludeFromRecents="true">
</activity>
- <activity android:name=".SmsDefaultDialog"
- android:label="@string/sms_application_title"
- android:excludeFromRecents="true"
- android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert">
- <intent-filter android:priority="1">
- <action android:name="android.provider.Telephony.ACTION_CHANGE_DEFAULT" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- </activity>
-
<activity
android:name="Settings$NotificationAccessSettingsActivity"
android:label="@string/manage_notification_access_title"
diff --git a/res/layout/video_preference.xml b/res/layout/video_preference.xml
index 17b867f..064596c 100644
--- a/res/layout/video_preference.xml
+++ b/res/layout/video_preference.xml
@@ -21,6 +21,7 @@
android:layout_height="wrap_content"
android:background="@color/gestures_setting_background_color"
android:clipToPadding="false"
+ android:clipChildren="true"
android:gravity="center"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:orientation="horizontal"
diff --git a/src/com/android/settings/SmsDefaultDialog.java b/src/com/android/settings/SmsDefaultDialog.java
deleted file mode 100644
index e856897..0000000
--- a/src/com/android/settings/SmsDefaultDialog.java
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * Copyright (C) 2013 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;
-
-import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-import android.provider.Telephony.Sms.Intents;
-import android.telephony.TelephonyManager;
-import android.text.TextUtils;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.Window;
-import android.view.WindowManager;
-import android.widget.BaseAdapter;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import com.android.internal.app.AlertActivity;
-import com.android.internal.app.AlertController;
-import com.android.internal.telephony.SmsApplication;
-import com.android.internal.telephony.SmsApplication.SmsApplicationData;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public final class SmsDefaultDialog extends AlertActivity implements
- DialogInterface.OnClickListener {
- private SmsApplicationData mNewSmsApplicationData;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Intent intent = getIntent();
- String packageName = intent.getStringExtra(Intents.EXTRA_PACKAGE_NAME);
-
- setResult(RESULT_CANCELED);
- if (!buildDialog(packageName)) {
- finish();
- }
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
- android.util.EventLog.writeEvent(0x534e4554, "120484087", -1, "");
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- final Window window = getWindow();
- final WindowManager.LayoutParams attrs = window.getAttributes();
- attrs.privateFlags &= ~SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
- window.setAttributes(attrs);
- }
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- switch (which) {
- case BUTTON_POSITIVE:
- SmsApplication.setDefaultApplication(mNewSmsApplicationData.mPackageName, this);
- setResult(RESULT_OK);
- break;
- case BUTTON_NEGATIVE:
- break;
- default:
- if (which >= 0) {
- AppListAdapter adapter = (AppListAdapter) mAlertParams.mAdapter;
- if (!adapter.isSelected(which)) {
- String packageName = adapter.getPackageName(which);
- if (!TextUtils.isEmpty(packageName)) {
- SmsApplication.setDefaultApplication(packageName, this);
- setResult(RESULT_OK);
- }
- }
- }
- break;
- }
- }
-
- private boolean buildDialog(String packageName) {
- TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
- if (!tm.isSmsCapable()) {
- // No phone, no SMS
- return false;
- }
- final AlertController.AlertParams p = mAlertParams;
- p.mTitle = getString(R.string.sms_change_default_dialog_title);
- mNewSmsApplicationData = SmsApplication.getSmsApplicationData(packageName, this);
- if (mNewSmsApplicationData != null) {
- // New default SMS app specified, change to that directly after the confirmation
- // dialog.
- SmsApplicationData oldSmsApplicationData = null;
- ComponentName oldSmsComponent = SmsApplication.getDefaultSmsApplication(this, true);
- if (oldSmsComponent != null) {
- oldSmsApplicationData = SmsApplication.getSmsApplicationData(
- oldSmsComponent.getPackageName(), this);
- if (oldSmsApplicationData.mPackageName.equals(
- mNewSmsApplicationData.mPackageName)) {
- return false;
- }
- }
-
- // Compose dialog; get
- if (oldSmsApplicationData != null) {
- p.mMessage = getString(R.string.sms_change_default_dialog_text,
- mNewSmsApplicationData.getApplicationName(this),
- oldSmsApplicationData.getApplicationName(this));
- } else {
- p.mMessage = getString(R.string.sms_change_default_no_previous_dialog_text,
- mNewSmsApplicationData.getApplicationName(this));
- }
- p.mPositiveButtonText = getString(R.string.yes);
- p.mNegativeButtonText = getString(R.string.no);
- p.mPositiveButtonListener = this;
- p.mNegativeButtonListener = this;
- } else {
- // No new default SMS app specified, show a list of all SMS apps and let user to pick
- p.mAdapter = new AppListAdapter();
- p.mOnClickListener = this;
- p.mNegativeButtonText = getString(R.string.cancel);
- p.mNegativeButtonListener = this;
- if (p.mAdapter.isEmpty()) {
- // If there is nothing to choose from, don't build the dialog.
- return false;
- }
- }
- setupAlert();
-
- return true;
- }
-
- /**
- * The list of SMS apps with label, icon. Current default SMS app is marked as "default".
- */
- private class AppListAdapter extends BaseAdapter {
- /**
- * SMS app item in the list
- */
- private class Item {
- final String label; // app label
- final Drawable icon; // app icon
- final String packgeName; // full app package name
-
- public Item(String label, Drawable icon, String packageName) {
- this.label = label;
- this.icon = icon;
- this.packgeName = packageName;
- }
- }
-
- // The list
- private final List<Item> mItems;
- // The index of selected
- private final int mSelectedIndex;
-
- public AppListAdapter() {
- mItems = getItems();
- int selected = getSelectedIndex();
- // Move selected up to the top so it is easy to find
- if (selected > 0) {
- Item item = mItems.remove(selected);
- mItems.add(0, item);
- selected = 0;
- }
- mSelectedIndex = selected;
- }
-
- @Override
- public int getCount() {
- return mItems != null ? mItems.size() : 0;
- }
-
- @Override
- public Object getItem(int position) {
- return mItems != null && position < mItems.size() ? mItems.get(position) : null;
- }
-
- @Override
- public long getItemId(int position) {
- return position;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- Item item = ((Item) getItem(position));
- LayoutInflater inflater = getLayoutInflater();
- View view = inflater.inflate(R.layout.app_preference_item, parent, false);
- TextView textView = (TextView) view.findViewById(android.R.id.title);
- textView.setText(item.label);
- if (position == mSelectedIndex) {
- view.findViewById(R.id.default_label).setVisibility(View.VISIBLE);
- } else {
- view.findViewById(R.id.default_label).setVisibility(View.GONE);
- }
- ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
- imageView.setImageDrawable(item.icon);
- return view;
- }
-
- /**
- * Get the selected package name by
- *
- * @param position the index of the item in the list
- * @return the package name of selected item
- */
- public String getPackageName(int position) {
- Item item = (Item) getItem(position);
- if (item != null) {
- return item.packgeName;
- }
- return null;
- }
-
- /**
- * Check if an item at a position is already selected
- *
- * @param position the index of the item in the list
- * @return true if the item at the position is already selected, false otherwise
- */
- public boolean isSelected(int position) {
- return position == mSelectedIndex;
- }
-
- // Get the list items by looking for SMS apps
- private List<Item> getItems() {
- PackageManager pm = getPackageManager();
- List<Item> items = new ArrayList<>();
- for (SmsApplication.SmsApplicationData app :
- SmsApplication.getApplicationCollection(SmsDefaultDialog.this)) {
- try {
- String packageName = app.mPackageName;
- ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0/*flags*/);
- if (appInfo != null) {
- items.add(new Item(
- appInfo.loadLabel(pm).toString(),
- appInfo.loadIcon(pm),
- packageName));
- }
- } catch (PackageManager.NameNotFoundException e) {
- // Ignore package can't be found
- }
- }
- return items;
- }
-
- // Get the selected item index by looking for the current default SMS app
- private int getSelectedIndex() {
- ComponentName appName = SmsApplication.getDefaultSmsApplication(
- SmsDefaultDialog.this, true);
- if (appName != null) {
- String defaultSmsAppPackageName = appName.getPackageName();
- if (!TextUtils.isEmpty(defaultSmsAppPackageName)) {
- for (int i = 0; i < mItems.size(); i++) {
- if (TextUtils.equals(mItems.get(i).packgeName, defaultSmsAppPackageName)) {
- return i;
- }
- }
- }
- }
- return -1;
- }
- }
-}
diff --git a/src/com/android/settings/password/ChooseLockGeneric.java b/src/com/android/settings/password/ChooseLockGeneric.java
index 7eb8dc2..2a7de05 100644
--- a/src/com/android/settings/password/ChooseLockGeneric.java
+++ b/src/com/android/settings/password/ChooseLockGeneric.java
@@ -25,6 +25,7 @@
import static com.android.settings.password.ChooseLockPassword.ChooseLockPasswordFragment.RESULT_FINISHED;
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
+import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_IS_CALLING_APP_ADMIN;
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
import android.accessibilityservice.AccessibilityServiceInfo;
@@ -169,6 +170,12 @@
/** From intent extra {@link ChooseLockSettingsHelper#EXTRA_KEY_CALLER_APP_NAME}. */
private String mCallerAppName = null;
+ /**
+ * The value from the intent extra {@link
+ * ChooseLockSettingsHelper#EXTRA_KEY_IS_CALLING_APP_ADMIN}.
+ */
+ private boolean mIsCallingAppAdmin;
+
protected boolean mForFingerprint = false;
protected boolean mForFace = false;
@@ -217,6 +224,8 @@
.getIntExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, PASSWORD_COMPLEXITY_NONE);
mCallerAppName =
getActivity().getIntent().getStringExtra(EXTRA_KEY_CALLER_APP_NAME);
+ mIsCallingAppAdmin = getActivity().getIntent()
+ .getBooleanExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN, /* defValue= */ false);
mForChangeCredRequiredForBoot = getArguments() != null && getArguments().getBoolean(
ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT);
mUserManager = UserManager.get(getActivity());
@@ -490,7 +499,7 @@
protected void addPreferences() {
addPreferencesFromResource(R.xml.security_settings_picker);
- if (!TextUtils.isEmpty(mCallerAppName)) {
+ if (!TextUtils.isEmpty(mCallerAppName) && !mIsCallingAppAdmin) {
FooterPreferenceMixinCompat footerMixin =
new FooterPreferenceMixinCompat(this, getSettingsLifecycle());
FooterPreference footer = footerMixin.createFooterPreference();
diff --git a/src/com/android/settings/password/ChooseLockSettingsHelper.java b/src/com/android/settings/password/ChooseLockSettingsHelper.java
index db12598..28ded2d 100644
--- a/src/com/android/settings/password/ChooseLockSettingsHelper.java
+++ b/src/com/android/settings/password/ChooseLockSettingsHelper.java
@@ -61,6 +61,12 @@
public static final String EXTRA_KEY_CALLER_APP_NAME = "caller_app_name";
/**
+ * Intent extra indicating that the calling app is an admin, such as a Device Adimn, Device
+ * Owner, or Profile Owner.
+ */
+ public static final String EXTRA_KEY_IS_CALLING_APP_ADMIN = "is_calling_app_admin";
+
+ /**
* When invoked via {@link ConfirmLockPassword.InternalActivity}, this flag
* controls if we relax the enforcement of
* {@link Utils#enforceSameOwner(android.content.Context, int)}.
diff --git a/src/com/android/settings/password/SetNewPasswordActivity.java b/src/com/android/settings/password/SetNewPasswordActivity.java
index 4722c56..055e5be 100644
--- a/src/com/android/settings/password/SetNewPasswordActivity.java
+++ b/src/com/android/settings/password/SetNewPasswordActivity.java
@@ -23,6 +23,7 @@
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
+import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_IS_CALLING_APP_ADMIN;
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
import android.app.Activity;
@@ -30,6 +31,8 @@
import android.app.admin.DevicePolicyManager.PasswordComplexity;
import android.app.admin.PasswordMetrics;
import android.app.settings.SettingsEnums;
+import android.content.ComponentName;
+import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
@@ -39,6 +42,8 @@
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import java.util.List;
+
/**
* Trampolines {@link DevicePolicyManager#ACTION_SET_NEW_PASSWORD} and
* {@link DevicePolicyManager#ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} intent to the appropriate UI
@@ -116,10 +121,28 @@
if (mRequestedMinComplexity != PASSWORD_COMPLEXITY_NONE) {
intent.putExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, mRequestedMinComplexity);
}
+ if (isCallingAppAdmin()) {
+ intent.putExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN, true);
+ }
startActivity(intent);
finish();
}
+ private boolean isCallingAppAdmin() {
+ DevicePolicyManager devicePolicyManager = getSystemService(DevicePolicyManager.class);
+ String callingAppPackageName = PasswordUtils.getCallingAppPackageName(getActivityToken());
+ List<ComponentName> admins = devicePolicyManager.getActiveAdmins();
+ if (admins == null) {
+ return false;
+ }
+ for (ComponentName componentName : admins) {
+ if (componentName.getPackageName().equals(callingAppPackageName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private void logSetNewPasswordIntent() {
final String callingAppPackageName =
PasswordUtils.getCallingAppPackageName(getActivityToken());
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
index c692f55..673c334 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
@@ -23,6 +23,7 @@
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
+import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_IS_CALLING_APP_ADMIN;
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
import static com.google.common.truth.Truth.assertThat;
@@ -182,13 +183,23 @@
CharSequence expectedTitle =
mActivity.getString(R.string.unlock_footer_none_complexity_requested, "app name");
- mFragment.updatePreferencesOrFinish(false /* isRecreatingActivity */);
+ mFragment.updatePreferencesOrFinish(/* isRecreatingActivity= */ false);
FooterPreference footer = mFragment.findPreference(FooterPreference.KEY_FOOTER);
assertThat(footer.getTitle()).isEqualTo(expectedTitle);
}
@Test
+ public void updatePreferencesOrFinish_callingAppIsAdmin_noFooter() {
+ initActivity(new Intent().putExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN, true));
+
+ mFragment.updatePreferencesOrFinish(/* isRecreatingActivity= */ false);
+
+ FooterPreference footer = mFragment.findPreference(FooterPreference.KEY_FOOTER);
+ assertThat(footer).isNull();
+ }
+
+ @Test
public void onActivityResult_requestcode0_shouldNotFinish() {
initActivity(null);
diff --git a/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java b/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java
index bed09cb..04a2157 100644
--- a/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java
@@ -24,6 +24,7 @@
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
+import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_IS_CALLING_APP_ADMIN;
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
import static com.google.common.truth.Truth.assertThat;
@@ -32,8 +33,10 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.app.admin.DevicePolicyManager;
import android.app.settings.SettingsEnums;
import android.content.ComponentName;
+import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
@@ -54,6 +57,8 @@
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;
+import org.robolectric.shadows.ShadowDevicePolicyManager;
+import org.robolectric.shadows.ShadowLog;
@RunWith(RobolectricTestRunner.class)
public class SetNewPasswordActivityTest {
@@ -91,7 +96,7 @@
Robolectric.buildActivity(SetNewPasswordActivity.class).get();
activity.launchChooseLock(new Bundle());
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
- Intent intent = shadowActivity.getNextStartedActivityForResult().intent;
+ Intent intent = getLaunchChooseLockIntent(shadowActivity);
assertThat(intent.getComponent())
.isEqualTo(new ComponentName(activity, ChooseLockGeneric.class));
@@ -105,7 +110,7 @@
Robolectric.buildActivity(SetNewPasswordActivity.class).get();
activity.launchChooseLock(new Bundle());
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
- Intent intent = shadowActivity.getNextStartedActivityForResult().intent;
+ Intent intent = getLaunchChooseLockIntent(shadowActivity);
assertThat(intent.getComponent())
.isEqualTo(new ComponentName(activity, SetupChooseLockGeneric.class));
@@ -149,7 +154,7 @@
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
- Intent actualIntent = shadowActivity.getNextStartedActivityForResult().intent;
+ Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PASSWORD);
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isTrue();
assertThat(actualIntent.getIntExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, PASSWORD_COMPLEXITY_NONE))
@@ -179,7 +184,7 @@
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
- Intent actualIntent = shadowActivity.getNextStartedActivityForResult().intent;
+ Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PASSWORD);
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
@@ -207,7 +212,7 @@
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
- Intent actualIntent = shadowActivity.getNextStartedActivityForResult().intent;
+ Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PASSWORD);
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
@@ -234,7 +239,7 @@
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
- Intent actualIntent = shadowActivity.getNextStartedActivityForResult().intent;
+ Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PASSWORD);
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
@@ -262,7 +267,7 @@
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
- Intent actualIntent = shadowActivity.getNextStartedActivityForResult().intent;
+ Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PARENT_PROFILE_PASSWORD);
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
@@ -289,7 +294,7 @@
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
- Intent actualIntent = shadowActivity.getNextStartedActivityForResult().intent;
+ Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PARENT_PROFILE_PASSWORD);
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
@@ -301,4 +306,45 @@
PKG_NAME,
Integer.MIN_VALUE);
}
+
+ @Test
+ @Config(shadows = {ShadowPasswordUtils.class})
+ public void launchChooseLock_callingAppIsAdmin_setsAdminExtra() {
+ SetNewPasswordActivity activity =
+ Robolectric.buildActivity(SetNewPasswordActivity.class).get();
+ DevicePolicyManager devicePolicyManager =
+ (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
+ Shadows.shadowOf(devicePolicyManager).setActiveAdmin(buildTestComponentName(PKG_NAME));
+ ShadowPasswordUtils.setCallingAppPackageName(PKG_NAME);
+
+ activity.launchChooseLock(new Bundle());
+
+ Intent intent = getLaunchChooseLockIntent(Shadows.shadowOf(activity));
+ assertThat(intent.hasExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN)).isTrue();
+ }
+
+ @Test
+ @Config(shadows = {ShadowPasswordUtils.class})
+ public void launchChooseLock_callingAppIsNotAdmin_doesNotSetAdminExtra() {
+ SetNewPasswordActivity activity =
+ Robolectric.buildActivity(SetNewPasswordActivity.class).get();
+ DevicePolicyManager devicePolicyManager =
+ (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
+ Shadows.shadowOf(devicePolicyManager)
+ .setActiveAdmin(buildTestComponentName("other_pkg_name"));
+ ShadowPasswordUtils.setCallingAppPackageName(PKG_NAME);
+
+ activity.launchChooseLock(new Bundle());
+
+ Intent intent = getLaunchChooseLockIntent(Shadows.shadowOf(activity));
+ assertThat(intent.hasExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN)).isFalse();
+ }
+
+ private ComponentName buildTestComponentName(String packageName) {
+ return new ComponentName(packageName, "clazz");
+ }
+
+ private Intent getLaunchChooseLockIntent(ShadowActivity shadowActivity) {
+ return shadowActivity.getNextStartedActivityForResult().intent;
+ }
}