1 /*
2  * Copyright (C) 2018 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.localtransport;
18 
19 import android.util.KeyValueSettingObserver;
20 import android.content.ContentResolver;
21 import android.os.Handler;
22 import android.provider.Settings;
23 import android.util.KeyValueListParser;
24 
25 public class LocalTransportParameters extends KeyValueSettingObserver {
26     private static final String TAG = "LocalTransportParams";
27     private static final String SETTING = Settings.Secure.BACKUP_LOCAL_TRANSPORT_PARAMETERS;
28     private static final String KEY_FAKE_ENCRYPTION_FLAG = "fake_encryption_flag";
29     private static final String KEY_NON_INCREMENTAL_ONLY = "non_incremental_only";
30     private static final String KEY_IS_DEVICE_TRANSFER = "is_device_transfer";
31     private static final String KEY_IS_ENCRYPTED = "is_encrypted";
32     private static final String KEY_LOG_AGENT_RESULTS = "log_agent_results";
33 
34     private boolean mFakeEncryptionFlag;
35     private boolean mIsNonIncrementalOnly;
36     private boolean mIsDeviceTransfer;
37     private boolean mIsEncrypted;
38     private boolean mLogAgentResults;
39 
LocalTransportParameters(Handler handler, ContentResolver resolver)40     public LocalTransportParameters(Handler handler, ContentResolver resolver) {
41         super(handler, resolver, Settings.Secure.getUriFor(SETTING));
42     }
43 
isFakeEncryptionFlag()44     boolean isFakeEncryptionFlag() {
45         return mFakeEncryptionFlag;
46     }
47 
isNonIncrementalOnly()48     boolean isNonIncrementalOnly() {
49         return mIsNonIncrementalOnly;
50     }
51 
isDeviceTransfer()52     boolean isDeviceTransfer() {
53         return mIsDeviceTransfer;
54     }
55 
isEncrypted()56     boolean isEncrypted() {
57         return mIsEncrypted;
58     }
59 
logAgentResults()60     boolean logAgentResults() {
61         return mLogAgentResults;
62     }
63 
getSettingValue(ContentResolver resolver)64     public String getSettingValue(ContentResolver resolver) {
65         return Settings.Secure.getString(resolver, SETTING);
66     }
67 
update(KeyValueListParser parser)68     public void update(KeyValueListParser parser) {
69         mFakeEncryptionFlag = parser.getBoolean(KEY_FAKE_ENCRYPTION_FLAG, false);
70         mIsNonIncrementalOnly = parser.getBoolean(KEY_NON_INCREMENTAL_ONLY, false);
71         mIsDeviceTransfer = parser.getBoolean(KEY_IS_DEVICE_TRANSFER, false);
72         mIsEncrypted = parser.getBoolean(KEY_IS_ENCRYPTED, false);
73         mLogAgentResults = parser.getBoolean(KEY_LOG_AGENT_RESULTS, /* def */ false);
74     }
75 }
76