Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f3c3a32 authored by Kenji Yokoyama's avatar Kenji Yokoyama Committed by Joey
Browse files

Automatically set SIM number to my profile

SIM number is automatically set as my phone number
when you see "My info" and editing the SIM number is prohibitted.

Bug: 28179542
Change-Id: If4b3d5e4e01e130f4c944625cc8e6f2ddd901c53
parent 704928be
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.util.Log;

import com.android.contacts.testing.InjectedServices;
import com.android.contacts.util.Constants;
import com.android.contacts.util.LocalProfile;
import com.android.contactsbind.analytics.AnalyticsUtil;

import com.google.common.annotations.VisibleForTesting;
@@ -130,7 +131,7 @@ public class ContactsApplication extends Application {
            // (and thus not have the get accounts permission).
            PreferenceManager.getDefaultSharedPreferences(context);
            getContentResolver().getType(ContentUris.withAppendedId(Contacts.CONTENT_URI, 1));

            LocalProfile.updateProfileWithSimNumber(context);
            return null;
        }

+59 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListPopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.android.contacts.ContactSaveService;
@@ -87,6 +88,7 @@ import com.android.contacts.util.ContactDisplayUtils;
import com.android.contacts.util.ContactPhotoUtils;
import com.android.contacts.util.ImplicitIntentsUtil;
import com.android.contacts.util.MaterialColorMapUtils;
import com.android.contacts.util.SimUtil;
import com.android.contacts.util.UiClosables;
import com.android.contactsbind.HelpUtils;

@@ -1282,6 +1284,9 @@ public class ContactEditorFragment extends Fragment implements
        editorView.setEnabled(mEnabled);
        editorView.setVisibility(View.VISIBLE);

        if (mIsUserProfile) {
            disableSimNumberEditingIfNeeded(editorView);
        }
        // Refresh the ActionBar as the visibility of the join command
        // Activity can be null if we have been detached from the Activity.
        invalidateOptionsMenu();
@@ -1747,4 +1752,58 @@ public class ContactEditorFragment extends Fragment implements
    private RawContactEditorView getContent() {
        return (RawContactEditorView) mContent;
    }

    public void disableSimNumberEditingIfNeeded(ViewGroup viewGroup) {
        KindSectionView phoneSectionView = getPhoneSectionView(viewGroup);
        disableSimNumberEditingIfNeeded(getContext(), phoneSectionView);
    }

    private KindSectionView getPhoneSectionView(ViewGroup viewGroup) {
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View child = viewGroup.getChildAt(i);
            if (child instanceof KindSectionView) {
                KindSectionView section = (KindSectionView)child;
                if (Phone.CONTENT_ITEM_TYPE.equals(section.getKind().mimeType)) {
                    return section;
                }
            } else if (child instanceof ViewGroup) {
                KindSectionView section = getPhoneSectionView((ViewGroup)child);
                if (section != null) {
                    return section;
                }
            }
        }
        return null;
    }

    private static void disableSimNumberEditingIfNeeded(Context context,
            KindSectionView phoneSectionView) {
        if (phoneSectionView == null) {
            return;
        }

        ViewGroup vg = (ViewGroup)phoneSectionView.findViewById(R.id.kind_editors);

        List<String> simNumbers = SimUtil.getLine1Numbers(context);

        for (String simNumber : simNumbers) {
            if (TextUtils.isEmpty(simNumber)) {
                continue;
            }
            TextFieldsEditorView row = null;
            for (int i = 0; i < vg.getChildCount(); i++) {
                row = (TextFieldsEditorView) vg.getChildAt(i);
                View editor = row.findViewById(R.id.editors);
                View editTextView = ((ViewGroup) editor).getChildAt(0);
                TextView editText = (TextView) editTextView;
                String number = editText.getText().toString();
                if (number.equals(simNumber)) {
                    row.setEnabled(false);
                    row.setAlpha(0.3f);
                    row.setDeleteButtonVisible(false);
                    break;
                }
            }
        }
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -580,4 +580,8 @@ public class KindSectionView extends LinearLayout {
        }
        return emptyEditors;
    }

    public DataKind getKind() {
        return mKindSectionData.getDataKind();
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.Directory;
import android.provider.ContactsContract.Groups;
import android.provider.ContactsContract.Profile;
import android.provider.ContactsContract.RawContacts;
import android.text.TextUtils;
import android.util.Log;
@@ -50,6 +51,7 @@ import com.android.contacts.model.dataitem.PhotoDataItem;
import com.android.contacts.util.Constants;
import com.android.contacts.util.ContactLoaderUtils;
import com.android.contacts.util.DataStatus;
import com.android.contacts.util.LocalProfile;
import com.android.contacts.util.UriUtils;

import com.google.common.collect.ImmutableList;
@@ -319,6 +321,9 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
                result = new Contact(mRequestedUri, cachedResult);
                resultIsCached = true;
            } else {
                if (mRequestedUri != null && Profile.CONTENT_URI.equals(mRequestedUri)) {
                    LocalProfile.updateProfileWithSimNumber(getContext());
                }
                if (uriCurrentFormat.getLastPathSegment().equals(Constants.LOOKUP_URI_ENCODED)) {
                    result = loadEncodedContactEntity(uriCurrentFormat, mLookupUri);
                } else {
+3 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.view.View;
import android.view.ViewGroup;

import com.android.contacts.R;
import com.android.contacts.activities.RequestPermissionsActivity;
import com.android.contacts.editor.SelectAccountDialogFragment;
import com.android.contacts.interactions.ImportDialogFragment;
import com.android.contacts.list.ProviderStatusWatcher;
@@ -67,6 +68,8 @@ public final class ContactsPreferenceActivity extends PreferenceActivity
        super.onCreate(savedInstanceState);
        mCompatDelegate.onCreate(savedInstanceState);

        // Request Requireied permission if needed
        RequestPermissionsActivity.startPermissionActivityIfNeeded(this);

        final ActionBar actionBar = mCompatDelegate.getSupportActionBar();
        if (actionBar != null) {
Loading