Home | History | Annotate | Download | only in comp
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.cts.comp;
     17 
     18 import android.content.Context;
     19 import android.os.Process;
     20 import android.os.UserHandle;
     21 import android.os.UserManager;
     22 import androidx.annotation.Nullable;
     23 import android.util.Log;
     24 
     25 import java.util.List;
     26 
     27 
     28 public class Utils {
     29 
     30     private static final String TAG = "BindDeviceAdminTest";
     31 
     32     /**
     33      * Returns the user handle of the other profile of the same user, or {@code null} if there
     34      * are no other profiles or there are more than one.
     35      */
     36     static @Nullable
     37     UserHandle getOtherProfile(Context context) {
     38         List<UserHandle> otherProfiles = context.getSystemService(UserManager.class)
     39                 .getUserProfiles();
     40         otherProfiles.remove(Process.myUserHandle());
     41         if (otherProfiles.size() == 1) {
     42             return otherProfiles.get(0);
     43         }
     44         Log.d(TAG, "There are " + otherProfiles.size() + " other profiles for user "
     45                 + Process.myUserHandle() + ": " + otherProfiles);
     46         return null;
     47     }
     48 }
     49