blob: 0992fcc5d68f62588a1d3701a739eb94f787aa94 [file] [log] [blame]
John Reck35e9dd62011-04-25 09:01:54 -07001
2/*
3 * Copyright (C) 2011 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Bijan Amirzada41242f22014-03-21 12:12:18 -070018package com.android.browser;
John Reck35e9dd62011-04-25 09:01:54 -070019
20import android.content.Context;
21import android.content.SharedPreferences;
22import android.content.SharedPreferences.Editor;
John Reck35e9dd62011-04-25 09:01:54 -070023import android.preference.PreferenceManager;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080024
John Reck35e9dd62011-04-25 09:01:54 -070025
John Reck7b06c902011-04-26 13:48:09 -070026import java.util.concurrent.CountDownLatch;
27
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080028import org.codeaurora.swe.AutoFillProfile;
29
30
John Reck35e9dd62011-04-25 09:01:54 -070031public class AutofillHandler {
32
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080033 protected AutoFillProfile mAutoFillProfile = null;
John Reck35e9dd62011-04-25 09:01:54 -070034 // Default to zero. In the case no profile is set up, the initial
35 // value will come from the AutoFillSettingsFragment when the user
36 // creates a profile. Otherwise, we'll read the ID of the last used
37 // profile from the prefs db.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080038 protected String mAutoFillActiveProfileId = "";
John Reck35e9dd62011-04-25 09:01:54 -070039 private static final int NO_AUTOFILL_PROFILE_SET = 0;
John Reck35e9dd62011-04-25 09:01:54 -070040 private Context mContext;
41
Ben Murdoch234eadc2012-05-14 16:39:50 +010042 private static final String LOGTAG = "AutofillHandler";
43
John Reck35e9dd62011-04-25 09:01:54 -070044 public AutofillHandler(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +010045 mContext = context.getApplicationContext();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080046 SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(mContext);
47 mAutoFillActiveProfileId = p.getString(
John Reck35e9dd62011-04-25 09:01:54 -070048 PreferenceKeys.PREF_AUTOFILL_ACTIVE_PROFILE_ID,
49 mAutoFillActiveProfileId);
John Reck35e9dd62011-04-25 09:01:54 -070050 }
51
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080052 public synchronized void setAutoFillProfile(AutoFillProfile profile) {
John Reck35e9dd62011-04-25 09:01:54 -070053 mAutoFillProfile = profile;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080054 if (profile == null)
55 setActiveAutoFillProfileId("");
56 else
57 setActiveAutoFillProfileId(profile.getUniqueId());
John Reck35e9dd62011-04-25 09:01:54 -070058 }
59
Ben Murdoch234eadc2012-05-14 16:39:50 +010060 public synchronized AutoFillProfile getAutoFillProfile() {
John Reck35e9dd62011-04-25 09:01:54 -070061 return mAutoFillProfile;
62 }
63
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080064 public synchronized String getAutoFillProfileId() {
65 return mAutoFillActiveProfileId;
66 }
67
68 private synchronized void setActiveAutoFillProfileId(String activeProfileId) {
69 if (mAutoFillActiveProfileId.equals(activeProfileId)) {
70 return;
71 }
John Reck35e9dd62011-04-25 09:01:54 -070072 mAutoFillActiveProfileId = activeProfileId;
73 Editor ed = PreferenceManager.
74 getDefaultSharedPreferences(mContext).edit();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080075 ed.putString(PreferenceKeys.PREF_AUTOFILL_ACTIVE_PROFILE_ID, activeProfileId);
John Reck35e9dd62011-04-25 09:01:54 -070076 ed.apply();
77 }
John Reck35e9dd62011-04-25 09:01:54 -070078}