2014-04-30 03:02:21 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2014 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.launcher3.compat;
|
|
|
|
|
|
2015-05-14 00:07:08 -07:00
|
|
|
import android.annotation.TargetApi;
|
2014-04-30 03:02:21 +01:00
|
|
|
import android.content.Context;
|
2015-04-08 18:13:46 -07:00
|
|
|
import android.content.SharedPreferences;
|
2014-09-05 15:59:00 -07:00
|
|
|
import android.content.pm.PackageManager;
|
2015-05-14 00:07:08 -07:00
|
|
|
import android.os.Build;
|
2014-04-30 03:02:21 +01:00
|
|
|
import android.os.UserHandle;
|
2015-08-04 11:40:13 -07:00
|
|
|
|
2015-08-21 09:23:44 -07:00
|
|
|
import com.android.launcher3.Utilities;
|
2015-08-04 11:40:13 -07:00
|
|
|
import com.android.launcher3.util.LongArrayMap;
|
|
|
|
|
|
2014-04-30 03:02:21 +01:00
|
|
|
import java.util.ArrayList;
|
2014-06-30 12:30:31 +01:00
|
|
|
import java.util.Collections;
|
2015-08-05 13:22:21 -07:00
|
|
|
import java.util.HashMap;
|
2014-04-30 03:02:21 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
2015-05-14 00:07:08 -07:00
|
|
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
2014-04-30 03:02:21 +01:00
|
|
|
public class UserManagerCompatVL extends UserManagerCompatV17 {
|
2015-04-08 18:13:46 -07:00
|
|
|
private static final String USER_CREATION_TIME_KEY = "user_creation_time_";
|
|
|
|
|
|
2014-09-05 15:59:00 -07:00
|
|
|
private final PackageManager mPm;
|
2015-04-08 18:13:46 -07:00
|
|
|
private final Context mContext;
|
2014-04-30 03:02:21 +01:00
|
|
|
|
|
|
|
|
UserManagerCompatVL(Context context) {
|
|
|
|
|
super(context);
|
2014-09-05 15:59:00 -07:00
|
|
|
mPm = context.getPackageManager();
|
2015-04-08 18:13:46 -07:00
|
|
|
mContext = context;
|
2014-04-30 03:02:21 +01:00
|
|
|
}
|
|
|
|
|
|
2015-08-04 11:40:13 -07:00
|
|
|
@Override
|
|
|
|
|
public void enableAndResetCache() {
|
|
|
|
|
synchronized (this) {
|
2015-08-05 13:22:21 -07:00
|
|
|
mUsers = new LongArrayMap<>();
|
|
|
|
|
mUserToSerialMap = new HashMap<>();
|
2015-08-04 11:40:13 -07:00
|
|
|
List<UserHandle> users = mUserManager.getUserProfiles();
|
|
|
|
|
if (users != null) {
|
|
|
|
|
for (UserHandle user : users) {
|
2015-08-05 13:22:21 -07:00
|
|
|
long serial = mUserManager.getSerialNumberForUser(user);
|
|
|
|
|
UserHandleCompat userCompat = UserHandleCompat.fromUser(user);
|
|
|
|
|
mUsers.put(serial, userCompat);
|
|
|
|
|
mUserToSerialMap.put(userCompat, serial);
|
2015-08-04 11:40:13 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-08 09:38:15 -07:00
|
|
|
@Override
|
2014-04-30 03:02:21 +01:00
|
|
|
public List<UserHandleCompat> getUserProfiles() {
|
2015-08-04 11:40:13 -07:00
|
|
|
synchronized (this) {
|
|
|
|
|
if (mUsers != null) {
|
|
|
|
|
List<UserHandleCompat> users = new ArrayList<>();
|
2015-08-05 13:22:21 -07:00
|
|
|
users.addAll(mUserToSerialMap.keySet());
|
2015-08-04 11:40:13 -07:00
|
|
|
return users;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 12:30:31 +01:00
|
|
|
List<UserHandle> users = mUserManager.getUserProfiles();
|
|
|
|
|
if (users == null) {
|
2015-06-10 16:00:42 -07:00
|
|
|
return Collections.emptyList();
|
2014-04-30 03:02:21 +01:00
|
|
|
}
|
2014-06-30 12:30:31 +01:00
|
|
|
ArrayList<UserHandleCompat> compatUsers = new ArrayList<UserHandleCompat>(
|
|
|
|
|
users.size());
|
|
|
|
|
for (UserHandle user : users) {
|
|
|
|
|
compatUsers.add(UserHandleCompat.fromUser(user));
|
|
|
|
|
}
|
|
|
|
|
return compatUsers;
|
2014-04-30 03:02:21 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-08 09:38:15 -07:00
|
|
|
@Override
|
2014-07-21 17:11:41 +01:00
|
|
|
public CharSequence getBadgedLabelForUser(CharSequence label, UserHandleCompat user) {
|
2014-06-30 12:30:31 +01:00
|
|
|
if (user == null) {
|
|
|
|
|
return label;
|
2014-04-30 03:02:21 +01:00
|
|
|
}
|
2014-09-09 15:23:00 -07:00
|
|
|
return mPm.getUserBadgedLabel(label, user.getUser());
|
2014-04-30 03:02:21 +01:00
|
|
|
}
|
2015-04-08 18:13:46 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public long getUserCreationTime(UserHandleCompat user) {
|
2015-08-21 09:23:44 -07:00
|
|
|
if (Utilities.ATLEAST_MARSHMALLOW) {
|
|
|
|
|
return mUserManager.getUserCreationTime(user.getUser());
|
|
|
|
|
}
|
2015-10-19 16:59:07 -07:00
|
|
|
SharedPreferences prefs = Utilities.getPrefs(mContext);
|
2015-04-08 18:13:46 -07:00
|
|
|
String key = USER_CREATION_TIME_KEY + getSerialNumberForUser(user);
|
|
|
|
|
if (!prefs.contains(key)) {
|
|
|
|
|
prefs.edit().putLong(key, System.currentTimeMillis()).apply();
|
|
|
|
|
}
|
|
|
|
|
return prefs.getLong(key, 0);
|
|
|
|
|
}
|
2014-04-30 03:02:21 +01:00
|
|
|
}
|
|
|
|
|
|