Show managed profile accounts on Settings > Factory Reset

List both primary profile's and managed profile's accounts. Also notify the user
if there are other users present on the device.

Bug: 17899181
Change-Id: I5401722e65305861edeed60cfe926fca5c81a418
This commit is contained in:
Zoltan Szatmary-Ban
2014-10-24 18:03:18 +01:00
parent 588611eea5
commit 7cc1b9e63e
3 changed files with 87 additions and 41 deletions

View File

@@ -57,6 +57,12 @@
<!-- Do not add any children here as they will be removed in the MasterClear.java
code. A list of accounts will be inserted programmatically. -->
</LinearLayout>
<TextView android:id="@+id/other_users_present"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:textSize="18sp"
android:text="@string/master_clear_other_users_present" />
<TextView android:id="@+id/erase_external_option_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@@ -2434,6 +2434,8 @@
<string name="master_clear_desc" product="default">"This will erase all data from your phone\'s <b>internal storage</b>, including:\n\n<li>Your Google account</li>\n<li>System and app data and settings</li>\n<li>Downloaded apps"</li></string>
<!-- SD card & phone storage settings screen, instructions and list of current accounts. The list of accounts follows this text[CHAR LIMIT=NONE] -->
<string name="master_clear_accounts" product="default">"\n\nYou are currently signed into the following accounts:\n"</string>
<!-- SD card & phone storage settings screen, notification if other users are present on the device [CHAR LIMIT=NONE] -->
<string name="master_clear_other_users_present" product="default">"\n\nThere are other users present on this device.\n"</string>
<!-- SD card & phone storage settings screen, list of items in user data storage (USB storage or SD card) that will be erased during this operation [CHAR LIMIT=NONE] -->
<string name="master_clear_desc_also_erases_external">"<li>Music</li>\n<li>Photos</li>\n<li>Other user data</li>"</string>
<!-- SD card & phone storage settings screen, instructions about whether to also erase the external storage (SD card) when erasing the internal storage [CHAR LIMIT=NONE] -->

View File

@@ -24,15 +24,19 @@ import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Environment;
import android.os.Process;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.preference.Preference;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -41,6 +45,8 @@ import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.List;
/**
* Confirm and execute a reset of the device to a clean "just out of the box"
* state. Multiple confirmations are required: first, a general "are you sure
@@ -164,7 +170,8 @@ public class MasterClear extends Fragment {
});
}
loadAccountList();
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
loadAccountList(um);
}
private boolean isExtStorageEncrypted() {
@@ -172,63 +179,85 @@ public class MasterClear extends Fragment {
return !"".equals(state);
}
private void loadAccountList() {
private void loadAccountList(final UserManager um) {
View accountsLabel = mContentView.findViewById(R.id.accounts_label);
LinearLayout contents = (LinearLayout)mContentView.findViewById(R.id.accounts);
contents.removeAllViews();
Context context = getActivity();
final List<UserInfo> profiles = um.getProfiles(UserHandle.myUserId());
final int profilesSize = profiles.size();
AccountManager mgr = AccountManager.get(context);
Account[] accounts = mgr.getAccounts();
final int N = accounts.length;
if (N == 0) {
accountsLabel.setVisibility(View.GONE);
contents.setVisibility(View.GONE);
return;
}
LayoutInflater inflater = (LayoutInflater)context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
AuthenticatorDescription[] descs = AccountManager.get(context).getAuthenticatorTypes();
final int M = descs.length;
for (int i=0; i<N; i++) {
Account account = accounts[i];
AuthenticatorDescription desc = null;
for (int j=0; j<M; j++) {
if (account.type.equals(descs[j].type)) {
desc = descs[j];
break;
}
}
if (desc == null) {
Log.w(TAG, "No descriptor for account name=" + account.name
+ " type=" + account.type);
int accountsCount = 0;
for (int profileIndex = 0; profileIndex < profilesSize; profileIndex++) {
final UserInfo userInfo = profiles.get(profileIndex);
final int profileId = userInfo.id;
final UserHandle userHandle = new UserHandle(profileId);
Account[] accounts = mgr.getAccountsAsUser(profileId);
final int N = accounts.length;
if (N == 0) {
continue;
}
Drawable icon = null;
try {
if (desc.iconId != 0) {
Context authContext = context.createPackageContext(desc.packageName, 0);
icon = authContext.getDrawable(desc.iconId);
}
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "No icon for account type " + desc.type);
}
accountsCount += N;
TextView child = (TextView)inflater.inflate(R.layout.master_clear_account,
contents, false);
child.setText(account.name);
if (icon != null) {
child.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
AuthenticatorDescription[] descs = AccountManager.get(context)
.getAuthenticatorTypesAsUser(profileId);
final int M = descs.length;
View titleView = newTitleView(contents, inflater);
final TextView titleText = (TextView) titleView.findViewById(android.R.id.title);
titleText.setText(userInfo.isManagedProfile() ? R.string.category_work
: R.string.category_personal);
contents.addView(titleView);
for (int i = 0; i < N; i++) {
Account account = accounts[i];
AuthenticatorDescription desc = null;
for (int j = 0; j < M; j++) {
if (account.type.equals(descs[j].type)) {
desc = descs[j];
break;
}
}
if (desc == null) {
Log.w(TAG, "No descriptor for account name=" + account.name
+ " type=" + account.type);
continue;
}
Drawable icon = null;
try {
if (desc.iconId != 0) {
Context authContext = context.createPackageContext(desc.packageName, 0);
icon = context.getPackageManager().getUserBadgedIcon(
authContext.getDrawable(desc.iconId), userHandle);
}
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "No icon for account type " + desc.type);
}
TextView child = (TextView)inflater.inflate(R.layout.master_clear_account,
contents, false);
child.setText(account.name);
if (icon != null) {
child.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
}
contents.addView(child);
}
contents.addView(child);
}
accountsLabel.setVisibility(View.VISIBLE);
contents.setVisibility(View.VISIBLE);
if (accountsCount > 0) {
accountsLabel.setVisibility(View.VISIBLE);
contents.setVisibility(View.VISIBLE);
}
// Checking for all other users and their profiles if any.
View otherUsers = mContentView.findViewById(R.id.other_users_present);
final boolean hasOtherUsers = (um.getUserCount() - profilesSize) > 0;
otherUsers.setVisibility(hasOtherUsers ? View.VISIBLE : View.GONE);
}
@Override
@@ -245,4 +274,13 @@ public class MasterClear extends Fragment {
establishInitialState();
return mContentView;
}
private View newTitleView(ViewGroup parent, LayoutInflater inflater) {
final TypedArray a = inflater.getContext().obtainStyledAttributes(null,
com.android.internal.R.styleable.Preference,
com.android.internal.R.attr.preferenceCategoryStyle, 0);
final int resId = a.getResourceId(com.android.internal.R.styleable.Preference_layout,
0);
return inflater.inflate(resId, parent, false);
}
}