blob: bb392e89f741cf48515f7e83a42f8bbce095176b [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;
23import android.database.Cursor;
Ben Murdoch3d6c7192011-10-27 18:04:58 +010024import android.net.Uri;
John Reck35e9dd62011-04-25 09:01:54 -070025import android.os.AsyncTask;
26import android.os.Message;
27import android.preference.PreferenceManager;
Ben Murdoch3d6c7192011-10-27 18:04:58 +010028import android.provider.ContactsContract;
Ben Murdoch234eadc2012-05-14 16:39:50 +010029import android.util.Log;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080030
John Reck35e9dd62011-04-25 09:01:54 -070031
John Reck7b06c902011-04-26 13:48:09 -070032import java.util.concurrent.CountDownLatch;
33
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080034import org.codeaurora.swe.AutoFillProfile;
35
36
John Reck35e9dd62011-04-25 09:01:54 -070037public class AutofillHandler {
38
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080039 protected AutoFillProfile mAutoFillProfile = null;
John Reck35e9dd62011-04-25 09:01:54 -070040 // Default to zero. In the case no profile is set up, the initial
41 // value will come from the AutoFillSettingsFragment when the user
42 // creates a profile. Otherwise, we'll read the ID of the last used
43 // profile from the prefs db.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080044 protected String mAutoFillActiveProfileId = "";
John Reck35e9dd62011-04-25 09:01:54 -070045 private static final int NO_AUTOFILL_PROFILE_SET = 0;
John Reck35e9dd62011-04-25 09:01:54 -070046 private Context mContext;
47
Ben Murdoch234eadc2012-05-14 16:39:50 +010048 private static final String LOGTAG = "AutofillHandler";
49
John Reck35e9dd62011-04-25 09:01:54 -070050 public AutofillHandler(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +010051 mContext = context.getApplicationContext();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080052 SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(mContext);
53 mAutoFillActiveProfileId = p.getString(
John Reck35e9dd62011-04-25 09:01:54 -070054 PreferenceKeys.PREF_AUTOFILL_ACTIVE_PROFILE_ID,
55 mAutoFillActiveProfileId);
John Reck35e9dd62011-04-25 09:01:54 -070056 }
57
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080058 public synchronized void setAutoFillProfile(AutoFillProfile profile) {
John Reck35e9dd62011-04-25 09:01:54 -070059 mAutoFillProfile = profile;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080060 if (profile == null)
61 setActiveAutoFillProfileId("");
62 else
63 setActiveAutoFillProfileId(profile.getUniqueId());
John Reck35e9dd62011-04-25 09:01:54 -070064 }
65
Ben Murdoch234eadc2012-05-14 16:39:50 +010066 public synchronized AutoFillProfile getAutoFillProfile() {
John Reck35e9dd62011-04-25 09:01:54 -070067 return mAutoFillProfile;
68 }
69
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080070 public synchronized String getAutoFillProfileId() {
71 return mAutoFillActiveProfileId;
72 }
73
74 private synchronized void setActiveAutoFillProfileId(String activeProfileId) {
75 if (mAutoFillActiveProfileId.equals(activeProfileId)) {
76 return;
77 }
John Reck35e9dd62011-04-25 09:01:54 -070078 mAutoFillActiveProfileId = activeProfileId;
79 Editor ed = PreferenceManager.
80 getDefaultSharedPreferences(mContext).edit();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080081 ed.putString(PreferenceKeys.PREF_AUTOFILL_ACTIVE_PROFILE_ID, activeProfileId);
John Reck35e9dd62011-04-25 09:01:54 -070082 ed.apply();
83 }
John Reck35e9dd62011-04-25 09:01:54 -070084}