• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.rkpdapp.testutil;
18 
19 import android.os.SystemProperties;
20 
21 public class SystemPropertySetter implements AutoCloseable {
22     final String mKey;
23     final String mOriginalValue;
24 
setHostname(String value)25     public static SystemPropertySetter setHostname(String value) {
26         return new SystemPropertySetter("remote_provisioning.hostname", value);
27     }
28 
setRkpOnly(String instanceName)29     public static SystemPropertySetter setRkpOnly(String instanceName) {
30         switch (instanceName) {
31             case "default":
32                 return new SystemPropertySetter("remote_provisioning.tee.rkp_only", "true");
33             case "strongbox":
34                 return new SystemPropertySetter("remote_provisioning.strongbox.rkp_only", "true");
35             default:
36                 throw new IllegalArgumentException("Unexpected instance: " + instanceName);
37         }
38     }
39 
SystemPropertySetter(String key, String value)40     private SystemPropertySetter(String key, String value) {
41         mKey = key;
42         mOriginalValue = SystemProperties.get(key, "");
43         SystemProperties.set(key, value);
44     }
45 
close()46     public void close() {
47         SystemProperties.set(mKey, mOriginalValue);
48     }
49 }
50