Create a simple fallback activity for supervised user creation
Create a simple fallback activity to be started if no other activity could be resolved when Add supervised user option is tapped in Multi User settings. Bug: 207495450 Test: croot && make RunSettingsRoboTests -j40 ROBOTEST_FILTER="com.android.settings.users.UserSettingsTest" Change-Id: I850a2798567787c2494c75aa5fa451ddf373410d
This commit is contained in:
@@ -2963,6 +2963,12 @@
|
|||||||
android:value="true" />
|
android:value="true" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".users.AddSupervisedUserActivity"
|
||||||
|
android:label="@*android:string/supervised_user_creation_label"
|
||||||
|
android:icon="@drawable/ic_settings_multiuser">
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="Settings$PaymentSettingsActivity"
|
android:name="Settings$PaymentSettingsActivity"
|
||||||
android:label="@string/nfc_payment_settings_title"
|
android:label="@string/nfc_payment_settings_title"
|
||||||
|
26
res/layout/add_supervised_user.xml
Normal file
26
res/layout/add_supervised_user.xml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (C) 2021 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<Button
|
||||||
|
android:id="@+id/createSupervisedUser"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:text="@*android:string/supervised_user_creation_label" />
|
||||||
|
</FrameLayout>
|
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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.users;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.os.NewUserRequest;
|
||||||
|
import android.os.NewUserResponse;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fallback activity for supervised user creation.
|
||||||
|
* Built to test {@link UserManager#createUser(NewUserRequest)} API.
|
||||||
|
*/
|
||||||
|
// TODO(b/209659998): [to-be-removed] fallback activity for supervised user creation.
|
||||||
|
public class AddSupervisedUserActivity extends Activity {
|
||||||
|
|
||||||
|
private UserManager mUserManager;
|
||||||
|
private ActivityManager mActivityManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
mUserManager = getSystemService(UserManager.class);
|
||||||
|
mActivityManager = getSystemService(ActivityManager.class);
|
||||||
|
setContentView(R.layout.add_supervised_user);
|
||||||
|
findViewById(R.id.createSupervisedUser).setOnClickListener(v -> createUser());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createUserAsync(final NewUserRequest request,
|
||||||
|
final Consumer<NewUserResponse> onResponse) {
|
||||||
|
Objects.requireNonNull(onResponse);
|
||||||
|
|
||||||
|
final Handler mMainThread = new Handler(Looper.getMainLooper());
|
||||||
|
Executors.newSingleThreadExecutor().execute(() -> {
|
||||||
|
final NewUserResponse response = mUserManager.createUser(request);
|
||||||
|
mMainThread.post(() -> onResponse.accept(response));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createUser() {
|
||||||
|
final NewUserRequest request = new NewUserRequest.Builder().build();
|
||||||
|
|
||||||
|
final AlertDialog pleaseWaitDialog = new AlertDialog.Builder(this)
|
||||||
|
.setMessage(getString(R.string.creating_new_user_dialog_message))
|
||||||
|
.setCancelable(false)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
pleaseWaitDialog.show();
|
||||||
|
createUserAsync(request, response -> {
|
||||||
|
pleaseWaitDialog.dismiss();
|
||||||
|
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
mActivityManager.switchUser(response.getUser());
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
|
new AlertDialog.Builder(this)
|
||||||
|
.setTitle(getString(R.string.add_user_failed))
|
||||||
|
.setMessage(UserManager.UserOperationResult.class.getName()
|
||||||
|
+ " = " + response.getOperationResult())
|
||||||
|
.setNeutralButton(getString(R.string.okay), null)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -504,6 +504,13 @@ public class UserSettings extends SettingsPreferenceFragment
|
|||||||
.setAction(UserManager.ACTION_CREATE_SUPERVISED_USER)
|
.setAction(UserManager.ACTION_CREATE_SUPERVISED_USER)
|
||||||
.setPackage(mConfigSupervisedUserCreationPackage);
|
.setPackage(mConfigSupervisedUserCreationPackage);
|
||||||
|
|
||||||
|
// TODO(b/209659998): [to-be-removed] fallback activity for supervised user creation.
|
||||||
|
if (getActivity().getPackageManager().resolveActivity(intent, 0) == null) {
|
||||||
|
intent
|
||||||
|
.setClass(getContext(), AddSupervisedUserActivity.class)
|
||||||
|
.setPackage(null);
|
||||||
|
}
|
||||||
|
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user