Merge "Rename ApexContext to ApexEnvironment." into rvc-dev am: e6dbe2b880 am: 86fe0229f1
Change-Id: Idec128b8850b4eff87cf0be47114e57f27686fc6
This commit is contained in:
@@ -18,7 +18,7 @@ package com.android.permission.persistence;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.ApexContext;
|
||||
import android.content.ApexEnvironment;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserHandle;
|
||||
import android.util.ArrayMap;
|
||||
@@ -258,8 +258,8 @@ public class RuntimePermissionsPersistenceImpl implements RuntimePermissionsPers
|
||||
|
||||
@NonNull
|
||||
private static File getFile(@NonNull UserHandle user) {
|
||||
ApexContext apexContext = ApexContext.getApexContext(APEX_MODULE_NAME);
|
||||
File dataDirectory = apexContext.getDeviceProtectedDataDirForUser(user);
|
||||
ApexEnvironment apexEnvironment = ApexEnvironment.getApexEnvironment(APEX_MODULE_NAME);
|
||||
File dataDirectory = apexEnvironment.getDeviceProtectedDataDirForUser(user);
|
||||
return new File(dataDirectory, RUNTIME_PERMISSIONS_FILE_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.android.role.persistence;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.ApexContext;
|
||||
import android.content.ApexEnvironment;
|
||||
import android.os.UserHandle;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
@@ -211,8 +211,8 @@ public class RolesPersistenceImpl implements RolesPersistence {
|
||||
|
||||
@NonNull
|
||||
private static File getFile(@NonNull UserHandle user) {
|
||||
ApexContext apexContext = ApexContext.getApexContext(APEX_MODULE_NAME);
|
||||
File dataDirectory = apexContext.getDeviceProtectedDataDirForUser(user);
|
||||
ApexEnvironment apexEnvironment = ApexEnvironment.getApexEnvironment(APEX_MODULE_NAME);
|
||||
File dataDirectory = apexEnvironment.getDeviceProtectedDataDirForUser(user);
|
||||
return new File(dataDirectory, ROLES_FILE_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1759,8 +1759,8 @@ package android.companion {
|
||||
|
||||
package android.content {
|
||||
|
||||
public class ApexContext {
|
||||
method @NonNull public static android.content.ApexContext getApexContext(@NonNull String);
|
||||
public class ApexEnvironment {
|
||||
method @NonNull public static android.content.ApexEnvironment getApexEnvironment(@NonNull String);
|
||||
method @NonNull public java.io.File getCredentialProtectedDataDirForUser(@NonNull android.os.UserHandle);
|
||||
method @NonNull public java.io.File getDeviceProtectedDataDir();
|
||||
method @NonNull public java.io.File getDeviceProtectedDataDirForUser(@NonNull android.os.UserHandle);
|
||||
|
||||
@@ -30,29 +30,29 @@ import java.util.Objects;
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public class ApexContext {
|
||||
public class ApexEnvironment {
|
||||
|
||||
private static final String APEX_DATA = "apexdata";
|
||||
|
||||
/**
|
||||
* Returns an ApexContext instance for the APEX with the provided {@code apexModuleName}.
|
||||
* Returns an ApexEnvironment instance for the APEX with the provided {@code apexModuleName}.
|
||||
*
|
||||
* <p>To preserve the safety and integrity of APEX modules, you must only obtain the ApexContext
|
||||
* for your specific APEX, and you <em>must never</em> attempt to obtain an ApexContext for
|
||||
* another APEX. Any coordination between APEXs must be performed through well-defined
|
||||
* interfaces; attempting to directly read or write raw files belonging to another APEX will
|
||||
* violate the hermetic storage requirements placed upon each module.
|
||||
* <p>To preserve the safety and integrity of APEX modules, you must only obtain the
|
||||
* ApexEnvironment for your specific APEX, and you <em>must never</em> attempt to obtain an
|
||||
* ApexEnvironment for another APEX. Any coordination between APEXs must be performed through
|
||||
* well-defined interfaces; attempting to directly read or write raw files belonging to another
|
||||
* APEX will violate the hermetic storage requirements placed upon each module.
|
||||
*/
|
||||
@NonNull
|
||||
public static ApexContext getApexContext(@NonNull String apexModuleName) {
|
||||
public static ApexEnvironment getApexEnvironment(@NonNull String apexModuleName) {
|
||||
Objects.requireNonNull(apexModuleName, "apexModuleName cannot be null");
|
||||
//TODO(b/141148175): Check that apexModuleName is an actual APEX name
|
||||
return new ApexContext(apexModuleName);
|
||||
return new ApexEnvironment(apexModuleName);
|
||||
}
|
||||
|
||||
private final String mApexModuleName;
|
||||
|
||||
private ApexContext(String apexModuleName) {
|
||||
private ApexEnvironment(String apexModuleName) {
|
||||
mApexModuleName = apexModuleName;
|
||||
}
|
||||
|
||||
@@ -28,20 +28,21 @@ import org.junit.runner.RunWith;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ApexContextTest {
|
||||
public class ApexEnvironmentTest {
|
||||
|
||||
@Test
|
||||
public void dataDirectoryPathsAreAsExpected() {
|
||||
ApexContext apexContext = ApexContext.getApexContext("my.apex");
|
||||
ApexEnvironment apexEnvironment = ApexEnvironment.getApexEnvironment("my.apex");
|
||||
|
||||
assertEquals("/data/misc/apexdata/my.apex",
|
||||
apexContext.getDeviceProtectedDataDir().getAbsolutePath());
|
||||
apexEnvironment.getDeviceProtectedDataDir().getAbsolutePath());
|
||||
|
||||
assertEquals("/data/misc_de/5/apexdata/my.apex",
|
||||
apexContext.getDeviceProtectedDataDirForUser(UserHandle.of(5)).getAbsolutePath());
|
||||
apexEnvironment
|
||||
.getDeviceProtectedDataDirForUser(UserHandle.of(5)).getAbsolutePath());
|
||||
|
||||
assertEquals("/data/misc_ce/16/apexdata/my.apex",
|
||||
apexContext.getCredentialProtectedDataDirForUser(
|
||||
apexEnvironment.getCredentialProtectedDataDirForUser(
|
||||
UserHandle.of(16)).getAbsolutePath());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user