Add utility to determine if account can't auto-sync due to roaming
* We need to call this out to the user (a surprised user is an unhappy user) * Required for fix to bug referenced below Bug: 5533550 Change-Id: I64a870a703de7e02ce882aefc3636a1668021eb8
This commit is contained in:
parent
d59affc5e6
commit
dea198bb04
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.emailcommon.provider;
|
||||
|
||||
import android.content.ContentProviderOperation;
|
||||
@ -8,6 +24,8 @@ import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.OperationApplicationException;
|
||||
import android.database.Cursor;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
@ -666,6 +684,34 @@ public final class Account extends EmailContent implements AccountColumns, Parce
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an account id, determine whether the account is currently prohibited from automatic
|
||||
* sync, due to roaming while the account's policy disables this
|
||||
* @param context the caller's context
|
||||
* @param accountId the account id
|
||||
* @return true if the account can't automatically sync due to roaming; false otherwise
|
||||
*/
|
||||
public static boolean isAutomaticSyncDisabledByRoaming(Context context, long accountId) {
|
||||
Account account = Account.restoreAccountWithId(context, accountId);
|
||||
// Account being deleted; just return
|
||||
if (account == null) return false;
|
||||
long policyKey = account.mPolicyKey;
|
||||
// If no security policy, we're good
|
||||
if (policyKey <= 0) return false;
|
||||
|
||||
ConnectivityManager cm =
|
||||
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo info = cm.getActiveNetworkInfo();
|
||||
// If we're not on mobile, we're good
|
||||
if (info == null || (info.getType() != ConnectivityManager.TYPE_MOBILE)) return false;
|
||||
// If we're not roaming, we're good
|
||||
if (!info.isRoaming()) return false;
|
||||
Policy policy = Policy.restorePolicyWithId(context, policyKey);
|
||||
// Account being deleted; just return
|
||||
if (policy == null) return false;
|
||||
return policy.mRequireManualSyncWhenRoaming;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override update to enforce a single default account, and do it atomically
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user