• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 com.android.test;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assume.assumeTrue;
22 
23 import android.platform.test.annotations.AppModeFull;
24 
25 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
26 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
27 import com.android.tradefed.testtype.junit4.DeviceTestRunOptions;
28 import com.android.tradefed.util.RunUtil;
29 
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 
33 import java.io.BufferedReader;
34 import java.io.StringReader;
35 
36 @RunWith(DeviceJUnit4ClassRunner.class)
37 public class CopyEfsTest extends BaseHostJUnit4Test {
38 
39 
40 
41 
42     @Test
43     @AppModeFull
copyEfsTest()44     public void copyEfsTest() throws Exception {
45 
46         getDevice().enableAdbRoot();
47 
48         // This test can be run on OEM unlocked device only as unlocking bootloader requires
49         // manual intervention.
50         String result = getDevice().getProperty("ro.boot.flash.locked");
51         assumeTrue("0".equals(result));
52         final String dataFstype = getFsTypeFor("/data");
53         assertTrue(!dataFstype.isEmpty());
54         if (!dataFstype.equals("ext4")) {
55             getDevice().executeShellCommand("cmd recovery wipe ext4");
56             RunUtil.getDefault().sleep(10000);
57             // Wait for 2 mins device to be online againg
58             getDevice().waitForDeviceOnline(120000);
59             getDevice().enableAdbRoot();
60         }
61         assertEquals("ext4", getFsTypeFor("/data"));
62         String dataBlockDev = getBlockDevFor("/data");
63         assertEquals(dataBlockDev, getBlockDevFor("/mnt/vendor/efs"));
64         assertEquals(dataBlockDev, getBlockDevFor("/mnt/vendor/efs_backup"));
65         assertEquals(dataBlockDev, getBlockDevFor("/mnt/vendor/modem_userdata"));
66     }
67 
getMountInfo(String mountPoint)68     private String[] getMountInfo(String mountPoint) throws Exception {
69         String result = getDevice().executeShellCommand("cat /proc/mounts");
70         BufferedReader br = new BufferedReader(new StringReader(result));
71         String line;
72         while ((line = br.readLine()) != null) {
73             final String[] fields = line.split(" ");
74             final String device = fields[0];
75             final String partition = fields[1];
76             final String fsType = fields[2];
77             if (partition.equals(mountPoint)) {
78                 return fields;
79             }
80         }
81         return null;
82     }
getFsTypeFor(String mountPoint)83     private String getFsTypeFor(String mountPoint) throws Exception {
84         String[] result = getMountInfo(mountPoint);
85         if (result == null) {
86             return "";
87         }
88         return result[2];
89     }
getBlockDevFor(String mountPoint)90     private String getBlockDevFor(String mountPoint) throws Exception {
91         String[] result = getMountInfo(mountPoint);
92         if (result == null) {
93             return "";
94         }
95         return result[0];
96     }
97 }
98