UserManagerCompatVL.java revision 7bc272a11b701a32d2ed91277341c382cbd84aeb
1 2/* 3 * Copyright (C) 2014 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package com.android.launcher3.compat; 19 20import android.content.Context; 21import android.graphics.drawable.Drawable; 22import android.os.UserHandle; 23import android.os.UserManager; 24 25import java.lang.reflect.InvocationTargetException; 26import java.lang.reflect.Method; 27import java.util.ArrayList; 28import java.util.List; 29 30public class UserManagerCompatVL extends UserManagerCompatV17 { 31 32 UserManagerCompatVL(Context context) { 33 super(context); 34 } 35 36 public List<UserHandleCompat> getUserProfiles() { 37 Method method = ReflectUtils.getMethod(mUserManager.getClass(), "getUserProfiles"); 38 if (method != null) { 39 List<UserHandle> users = (List<UserHandle>) ReflectUtils.invokeMethod( 40 mUserManager, method); 41 if (users != null) { 42 ArrayList<UserHandleCompat> compatUsers = new ArrayList<UserHandleCompat>( 43 users.size()); 44 for (UserHandle user : users) { 45 compatUsers.add(UserHandleCompat.fromUser(user)); 46 } 47 return compatUsers; 48 } 49 } 50 // Fall back to non L version. 51 return super.getUserProfiles(); 52 } 53 54 public Drawable getBadgedDrawableForUser(Drawable unbadged, UserHandleCompat user) { 55 Method method = ReflectUtils.getMethod(mUserManager.getClass(), "getBadgedDrawableForUser", 56 Drawable.class, UserHandle.class); 57 if (method != null) { 58 Drawable d = (Drawable) ReflectUtils.invokeMethod(mUserManager, method, unbadged, 59 user.getUser()); 60 if (d != null) { 61 return d; 62 } 63 } 64 // Fall back to non L version. 65 return super.getBadgedDrawableForUser(unbadged, user); 66 } 67} 68 69