Home | History | Annotate | Download | only in profileserialnumberapp
      1 /*
      2  * Copyright (C) 2019 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 
     17 package android.cts.backup.profileserialnumberapp;
     18 
     19 import static androidx.test.InstrumentationRegistry.getInstrumentation;
     20 
     21 import static org.junit.Assert.assertEquals;
     22 import static org.junit.Assert.assertNull;
     23 
     24 import android.app.backup.BackupManager;
     25 import android.os.Binder;
     26 import android.platform.test.annotations.AppModeFull;
     27 
     28 import androidx.test.runner.AndroidJUnit4;
     29 
     30 import com.android.compatibility.common.util.SystemUtil;
     31 
     32 import org.junit.Before;
     33 import org.junit.Test;
     34 import org.junit.runner.RunWith;
     35 
     36 /** Device side test invoked by ProfileSerialNumberHostSideTest. */
     37 @AppModeFull
     38 @RunWith(AndroidJUnit4.class)
     39 public class ProfileSerialNumberTest {
     40     private static final long USER_SERIAL_NUMBER = 124;
     41     private static final long INVALID_USER_SERIAL_NUMBER = -1000;
     42 
     43     private BackupManager mBackupManager;
     44 
     45     @Before
     46     public void setUp() throws Exception {
     47         mBackupManager = new BackupManager(getInstrumentation().getTargetContext());
     48     }
     49 
     50     @Test
     51     public void testSetAndGetAncestralSerialNumber() {
     52         SystemUtil.runWithShellPermissionIdentity(() -> {
     53             mBackupManager.setAncestralSerialNumber(USER_SERIAL_NUMBER);
     54         });
     55 
     56         assertEquals(Binder.getCallingUserHandle(),
     57                 mBackupManager.getUserForAncestralSerialNumber(USER_SERIAL_NUMBER));
     58     }
     59 
     60     @Test
     61     public void testGetUserForAncestralSerialNumber_returnsNull_whenNoUserHasGivenSerialNumber() {
     62         assertNull(mBackupManager.getUserForAncestralSerialNumber(INVALID_USER_SERIAL_NUMBER));
     63     }
     64 }
     65