forked from upstream-mirrors/quik
add delay send mms. add group send to individual recipients - sms and mms. add immediate show messages in convo, not wait for sent. new qktransaction that replaces android/smsmms transaction with mods for quik. lots of code cleanups and removing superfluous code. some bug fixes.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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 android.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates a constant field value should be exported to be used in the SDK tools.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface SdkConstant {
|
||||
public static enum SdkConstantType {
|
||||
ACTIVITY_INTENT_ACTION, BROADCAST_INTENT_ACTION, SERVICE_ACTION, INTENT_CATEGORY, FEATURE;
|
||||
}
|
||||
|
||||
SdkConstantType value();
|
||||
}
|
||||
Executable → Regular
+18
-7
@@ -22,15 +22,16 @@ import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.widget.Toast;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import timber.log.Timber;
|
||||
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
|
||||
public final class SqliteWrapper {
|
||||
private static final String TAG = "SqliteWrapper";
|
||||
private static final String SQLITE_EXCEPTION_DETAIL_MESSAGE
|
||||
= "unable to open database file";
|
||||
|
||||
@@ -52,24 +53,34 @@ public final class SqliteWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Cursor query(Context context, ContentResolver resolver, Uri uri,
|
||||
String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||
try {
|
||||
return resolver.query(uri, projection, selection, selectionArgs, sortOrder);
|
||||
} catch (SQLiteException e) {
|
||||
Timber.e(e, "Catch a SQLiteException when query: ");
|
||||
Timber.e("Catch a SQLiteException when query: ", e);
|
||||
checkSQLiteException(context, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static boolean requery(Context context, Cursor cursor) {
|
||||
try {
|
||||
return cursor.requery();
|
||||
} catch (SQLiteException e) {
|
||||
Timber.e("Catch a SQLiteException when requery: ", e);
|
||||
checkSQLiteException(context, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static int update(Context context, ContentResolver resolver, Uri uri,
|
||||
ContentValues values, String where, String[] selectionArgs) {
|
||||
try {
|
||||
return resolver.update(uri, values, where, selectionArgs);
|
||||
} catch (SQLiteException e) {
|
||||
Timber.e(e, "Catch a SQLiteException when update: ");
|
||||
Timber.e("Catch a SQLiteException when update: ", e);
|
||||
checkSQLiteException(context, e);
|
||||
return -1;
|
||||
}
|
||||
@@ -80,7 +91,7 @@ public final class SqliteWrapper {
|
||||
try {
|
||||
return resolver.delete(uri, where, selectionArgs);
|
||||
} catch (SQLiteException e) {
|
||||
Timber.e(e, "Catch a SQLiteException when delete: ");
|
||||
Timber.e("Catch a SQLiteException when delete: ", e);
|
||||
checkSQLiteException(context, e);
|
||||
return -1;
|
||||
}
|
||||
@@ -91,7 +102,7 @@ public final class SqliteWrapper {
|
||||
try {
|
||||
return resolver.insert(uri, values);
|
||||
} catch (SQLiteException e) {
|
||||
Timber.e(e, "Catch a SQLiteException when insert: ");
|
||||
Timber.e("Catch a SQLiteException when insert: ", e);
|
||||
checkSQLiteException(context, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
Executable → Regular
+5
-4
@@ -17,7 +17,7 @@
|
||||
package android.net;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import timber.log.Timber;
|
||||
import timber.log.Timber; import android.util.Log; import static com.klinker.android.timberworkarounds.TimberExtensionsKt.Timber_isLoggable; // inserted with sed
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
@@ -32,6 +32,7 @@ import java.util.Collections;
|
||||
* @hide
|
||||
*/
|
||||
public class DhcpInfoInternal {
|
||||
private final static String TAG = "DhcpInfoInternal";
|
||||
public String ipAddress;
|
||||
public int prefixLength;
|
||||
|
||||
@@ -95,7 +96,7 @@ public class DhcpInfoInternal {
|
||||
|
||||
public LinkAddress makeLinkAddress() {
|
||||
if (TextUtils.isEmpty(ipAddress)) {
|
||||
Timber.e("makeLinkAddress with empty ipAddress");
|
||||
Log.e(TAG, "makeLinkAddress with empty ipAddress");
|
||||
return null;
|
||||
}
|
||||
return new LinkAddress(NetworkUtilsHelper.numericToInetAddress(ipAddress), prefixLength);
|
||||
@@ -111,12 +112,12 @@ public class DhcpInfoInternal {
|
||||
if (TextUtils.isEmpty(dns1) == false) {
|
||||
p.addDns(NetworkUtilsHelper.numericToInetAddress(dns1));
|
||||
} else {
|
||||
Timber.d("makeLinkProperties with empty dns1!");
|
||||
Log.d(TAG, "makeLinkProperties with empty dns1!");
|
||||
}
|
||||
if (TextUtils.isEmpty(dns2) == false) {
|
||||
p.addDns(NetworkUtilsHelper.numericToInetAddress(dns2));
|
||||
} else {
|
||||
Timber.d("makeLinkProperties with empty dns2!");
|
||||
Log.d(TAG, "makeLinkProperties with empty dns2!");
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Executable → Regular
@@ -0,0 +1,494 @@
|
||||
/*
|
||||
* This file is auto-generated. DO NOT MODIFY.
|
||||
* Original file: frameworks/base/core/java/android/net/INetworkPolicyManager.aidl
|
||||
*/
|
||||
package android.net;
|
||||
|
||||
/**
|
||||
* Interface that creates and modifies network policy rules.
|
||||
* <p/>
|
||||
* {@hide}
|
||||
*/
|
||||
public interface INetworkPolicyManager extends android.os.IInterface {
|
||||
/**
|
||||
* Local-side IPC implementation stub class.
|
||||
*/
|
||||
public static abstract class Stub extends android.os.Binder implements android.net.INetworkPolicyManager {
|
||||
private static final java.lang.String DESCRIPTOR = "android.net.INetworkPolicyManager";
|
||||
|
||||
/**
|
||||
* Construct the stub at attach it to the interface.
|
||||
*/
|
||||
public Stub() {
|
||||
this.attachInterface(this, DESCRIPTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast an IBinder object into an android.net.INetworkPolicyManager interface,
|
||||
* generating a proxy if needed.
|
||||
*/
|
||||
public static android.net.INetworkPolicyManager asInterface(android.os.IBinder obj) {
|
||||
if ((obj == null)) {
|
||||
return null;
|
||||
}
|
||||
android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
|
||||
if (((iin != null) && (iin instanceof android.net.INetworkPolicyManager))) {
|
||||
return ((android.net.INetworkPolicyManager) iin);
|
||||
}
|
||||
return new android.net.INetworkPolicyManager.Stub.Proxy(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.os.IBinder asBinder() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException {
|
||||
switch (code) {
|
||||
case INTERFACE_TRANSACTION: {
|
||||
reply.writeString(DESCRIPTOR);
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_setUidPolicy: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
int _arg0;
|
||||
_arg0 = data.readInt();
|
||||
int _arg1;
|
||||
_arg1 = data.readInt();
|
||||
this.setUidPolicy(_arg0, _arg1);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_getUidPolicy: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
int _arg0;
|
||||
_arg0 = data.readInt();
|
||||
int _result = this.getUidPolicy(_arg0);
|
||||
reply.writeNoException();
|
||||
reply.writeInt(_result);
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_getUidsWithPolicy: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
int _arg0;
|
||||
_arg0 = data.readInt();
|
||||
int[] _result = this.getUidsWithPolicy(_arg0);
|
||||
reply.writeNoException();
|
||||
reply.writeIntArray(_result);
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_isUidForeground: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
int _arg0;
|
||||
_arg0 = data.readInt();
|
||||
boolean _result = this.isUidForeground(_arg0);
|
||||
reply.writeNoException();
|
||||
reply.writeInt(((_result) ? (1) : (0)));
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_registerListener: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.INetworkPolicyListener _arg0;
|
||||
_arg0 = android.net.INetworkPolicyListener.Stub.asInterface(data.readStrongBinder());
|
||||
this.registerListener(_arg0);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_unregisterListener: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.INetworkPolicyListener _arg0;
|
||||
_arg0 = android.net.INetworkPolicyListener.Stub.asInterface(data.readStrongBinder());
|
||||
this.unregisterListener(_arg0);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_setNetworkPolicies: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.NetworkPolicy[] _arg0;
|
||||
_arg0 = data.createTypedArray(android.net.NetworkPolicy.CREATOR);
|
||||
this.setNetworkPolicies(_arg0);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_getNetworkPolicies: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.NetworkPolicy[] _result = this.getNetworkPolicies();
|
||||
reply.writeNoException();
|
||||
reply.writeTypedArray(_result, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_snoozeLimit: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.NetworkTemplate _arg0;
|
||||
if ((0 != data.readInt())) {
|
||||
_arg0 = android.net.NetworkTemplate.CREATOR.createFromParcel(data);
|
||||
} else {
|
||||
_arg0 = null;
|
||||
}
|
||||
this.snoozeLimit(_arg0);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_setRestrictBackground: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
boolean _arg0;
|
||||
_arg0 = (0 != data.readInt());
|
||||
this.setRestrictBackground(_arg0);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_getRestrictBackground: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
boolean _result = this.getRestrictBackground();
|
||||
reply.writeNoException();
|
||||
reply.writeInt(((_result) ? (1) : (0)));
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_getNetworkQuotaInfo: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.NetworkState _arg0;
|
||||
if ((0 != data.readInt())) {
|
||||
_arg0 = android.net.NetworkState.CREATOR.createFromParcel(data);
|
||||
} else {
|
||||
_arg0 = null;
|
||||
}
|
||||
android.net.NetworkQuotaInfo _result = this.getNetworkQuotaInfo(_arg0);
|
||||
reply.writeNoException();
|
||||
if ((_result != null)) {
|
||||
reply.writeInt(1);
|
||||
_result.writeToParcel(reply, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
|
||||
} else {
|
||||
reply.writeInt(0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_isNetworkMetered: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.NetworkState _arg0;
|
||||
if ((0 != data.readInt())) {
|
||||
_arg0 = android.net.NetworkState.CREATOR.createFromParcel(data);
|
||||
} else {
|
||||
_arg0 = null;
|
||||
}
|
||||
boolean _result = this.isNetworkMetered(_arg0);
|
||||
reply.writeNoException();
|
||||
reply.writeInt(((_result) ? (1) : (0)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onTransact(code, data, reply, flags);
|
||||
}
|
||||
|
||||
private static class Proxy implements android.net.INetworkPolicyManager {
|
||||
private android.os.IBinder mRemote;
|
||||
|
||||
Proxy(android.os.IBinder remote) {
|
||||
mRemote = remote;
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.os.IBinder asBinder() {
|
||||
return mRemote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Control UID policies.
|
||||
*/
|
||||
@Override
|
||||
public void setUidPolicy(int uid, int policy) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeInt(uid);
|
||||
_data.writeInt(policy);
|
||||
mRemote.transact(Stub.TRANSACTION_setUidPolicy, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUidPolicy(int uid) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
int _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeInt(uid);
|
||||
mRemote.transact(Stub.TRANSACTION_getUidPolicy, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = _reply.readInt();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getUidsWithPolicy(int policy) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
int[] _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeInt(policy);
|
||||
mRemote.transact(Stub.TRANSACTION_getUidsWithPolicy, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = _reply.createIntArray();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUidForeground(int uid) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
boolean _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeInt(uid);
|
||||
mRemote.transact(Stub.TRANSACTION_isUidForeground, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = (0 != _reply.readInt());
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerListener(android.net.INetworkPolicyListener listener) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeStrongBinder((((listener != null)) ? (listener.asBinder()) : (null)));
|
||||
mRemote.transact(Stub.TRANSACTION_registerListener, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterListener(android.net.INetworkPolicyListener listener) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeStrongBinder((((listener != null)) ? (listener.asBinder()) : (null)));
|
||||
mRemote.transact(Stub.TRANSACTION_unregisterListener, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Control network policies atomically.
|
||||
*/
|
||||
@Override
|
||||
public void setNetworkPolicies(android.net.NetworkPolicy[] policies) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeTypedArray(policies, 0);
|
||||
mRemote.transact(Stub.TRANSACTION_setNetworkPolicies, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.net.NetworkPolicy[] getNetworkPolicies() throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
android.net.NetworkPolicy[] _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
mRemote.transact(Stub.TRANSACTION_getNetworkPolicies, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = _reply.createTypedArray(android.net.NetworkPolicy.CREATOR);
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Snooze limit on policy matching given template.
|
||||
*/
|
||||
@Override
|
||||
public void snoozeLimit(android.net.NetworkTemplate template) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
if ((template != null)) {
|
||||
_data.writeInt(1);
|
||||
template.writeToParcel(_data, 0);
|
||||
} else {
|
||||
_data.writeInt(0);
|
||||
}
|
||||
mRemote.transact(Stub.TRANSACTION_snoozeLimit, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Control if background data is restricted system-wide.
|
||||
*/
|
||||
@Override
|
||||
public void setRestrictBackground(boolean restrictBackground) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeInt(((restrictBackground) ? (1) : (0)));
|
||||
mRemote.transact(Stub.TRANSACTION_setRestrictBackground, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRestrictBackground() throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
boolean _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
mRemote.transact(Stub.TRANSACTION_getRestrictBackground, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = (0 != _reply.readInt());
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.net.NetworkQuotaInfo getNetworkQuotaInfo(android.net.NetworkState state) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
android.net.NetworkQuotaInfo _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
if ((state != null)) {
|
||||
_data.writeInt(1);
|
||||
state.writeToParcel(_data, 0);
|
||||
} else {
|
||||
_data.writeInt(0);
|
||||
}
|
||||
mRemote.transact(Stub.TRANSACTION_getNetworkQuotaInfo, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
if ((0 != _reply.readInt())) {
|
||||
_result = android.net.NetworkQuotaInfo.CREATOR.createFromParcel(_reply);
|
||||
} else {
|
||||
_result = null;
|
||||
}
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNetworkMetered(android.net.NetworkState state) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
boolean _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
if ((state != null)) {
|
||||
_data.writeInt(1);
|
||||
state.writeToParcel(_data, 0);
|
||||
} else {
|
||||
_data.writeInt(0);
|
||||
}
|
||||
mRemote.transact(Stub.TRANSACTION_isNetworkMetered, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = (0 != _reply.readInt());
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
}
|
||||
|
||||
static final int TRANSACTION_setUidPolicy = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
|
||||
static final int TRANSACTION_getUidPolicy = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
|
||||
static final int TRANSACTION_getUidsWithPolicy = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
|
||||
static final int TRANSACTION_isUidForeground = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3);
|
||||
static final int TRANSACTION_registerListener = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4);
|
||||
static final int TRANSACTION_unregisterListener = (android.os.IBinder.FIRST_CALL_TRANSACTION + 5);
|
||||
static final int TRANSACTION_setNetworkPolicies = (android.os.IBinder.FIRST_CALL_TRANSACTION + 6);
|
||||
static final int TRANSACTION_getNetworkPolicies = (android.os.IBinder.FIRST_CALL_TRANSACTION + 7);
|
||||
static final int TRANSACTION_snoozeLimit = (android.os.IBinder.FIRST_CALL_TRANSACTION + 8);
|
||||
static final int TRANSACTION_setRestrictBackground = (android.os.IBinder.FIRST_CALL_TRANSACTION + 9);
|
||||
static final int TRANSACTION_getRestrictBackground = (android.os.IBinder.FIRST_CALL_TRANSACTION + 10);
|
||||
static final int TRANSACTION_getNetworkQuotaInfo = (android.os.IBinder.FIRST_CALL_TRANSACTION + 11);
|
||||
static final int TRANSACTION_isNetworkMetered = (android.os.IBinder.FIRST_CALL_TRANSACTION + 12);
|
||||
}
|
||||
|
||||
/**
|
||||
* Control UID policies.
|
||||
*/
|
||||
public void setUidPolicy(int uid, int policy) throws android.os.RemoteException;
|
||||
|
||||
public int getUidPolicy(int uid) throws android.os.RemoteException;
|
||||
|
||||
public int[] getUidsWithPolicy(int policy) throws android.os.RemoteException;
|
||||
|
||||
public boolean isUidForeground(int uid) throws android.os.RemoteException;
|
||||
|
||||
public void registerListener(android.net.INetworkPolicyListener listener) throws android.os.RemoteException;
|
||||
|
||||
public void unregisterListener(android.net.INetworkPolicyListener listener) throws android.os.RemoteException;
|
||||
|
||||
/**
|
||||
* Control network policies atomically.
|
||||
*/
|
||||
public void setNetworkPolicies(android.net.NetworkPolicy[] policies) throws android.os.RemoteException;
|
||||
|
||||
public android.net.NetworkPolicy[] getNetworkPolicies() throws android.os.RemoteException;
|
||||
|
||||
/**
|
||||
* Snooze limit on policy matching given template.
|
||||
*/
|
||||
public void snoozeLimit(android.net.NetworkTemplate template) throws android.os.RemoteException;
|
||||
|
||||
/**
|
||||
* Control if background data is restricted system-wide.
|
||||
*/
|
||||
public void setRestrictBackground(boolean restrictBackground) throws android.os.RemoteException;
|
||||
|
||||
public boolean getRestrictBackground() throws android.os.RemoteException;
|
||||
|
||||
public android.net.NetworkQuotaInfo getNetworkQuotaInfo(android.net.NetworkState state) throws android.os.RemoteException;
|
||||
|
||||
public boolean isNetworkMetered(android.net.NetworkState state) throws android.os.RemoteException;
|
||||
}
|
||||
Executable → Regular
Executable → Regular
+2
-1
@@ -18,7 +18,7 @@ package android.net;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import timber.log.Timber;
|
||||
import timber.log.Timber; import android.util.Log; import static com.klinker.android.timberworkarounds.TimberExtensionsKt.Timber_isLoggable; // inserted with sed
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -32,6 +32,7 @@ import java.util.Set;
|
||||
* @hide
|
||||
*/
|
||||
public class LinkCapabilities implements Parcelable {
|
||||
private static final String TAG = "LinkCapabilities";
|
||||
private static final boolean DBG = false;
|
||||
|
||||
/**
|
||||
|
||||
Executable → Regular
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* 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 android.net;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.telephony.TelephonyManager;
|
||||
import com.android.internal.util.Objects;
|
||||
|
||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
|
||||
/**
|
||||
* Network definition that includes strong identity. Analogous to combining
|
||||
* {@link NetworkInfo} and an IMSI.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public class NetworkIdentity {
|
||||
/**
|
||||
* When enabled, combine all {@link #mSubType} together under
|
||||
* {@link #SUBTYPE_COMBINED}.
|
||||
*/
|
||||
public static final boolean COMBINE_SUBTYPE_ENABLED = true;
|
||||
|
||||
public static final int SUBTYPE_COMBINED = -1;
|
||||
|
||||
final int mType;
|
||||
final int mSubType;
|
||||
final String mSubscriberId;
|
||||
final String mNetworkId;
|
||||
final boolean mRoaming;
|
||||
|
||||
public NetworkIdentity(
|
||||
int type, int subType, String subscriberId, String networkId, boolean roaming) {
|
||||
mType = type;
|
||||
mSubType = COMBINE_SUBTYPE_ENABLED ? SUBTYPE_COMBINED : subType;
|
||||
mSubscriberId = subscriberId;
|
||||
mNetworkId = networkId;
|
||||
mRoaming = roaming;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@hide}
|
||||
*/
|
||||
public static String getNetworkTypeName(int type) {
|
||||
switch (type) {
|
||||
case 0:
|
||||
return "MOBILE";
|
||||
case TYPE_WIFI:
|
||||
return "WIFI";
|
||||
case 2:
|
||||
return "MOBILE_MMS";
|
||||
case 3:
|
||||
return "MOBILE_SUPL";
|
||||
case 4:
|
||||
return "MOBILE_DUN";
|
||||
case 5:
|
||||
return "MOBILE_HIPRI";
|
||||
case 6:
|
||||
return "WIMAX";
|
||||
case 7:
|
||||
return "BLUETOOTH";
|
||||
case 8:
|
||||
return "DUMMY";
|
||||
case 9:
|
||||
return "ETHERNET";
|
||||
case 10:
|
||||
return "MOBILE_FOTA";
|
||||
case 11:
|
||||
return "MOBILE_IMS";
|
||||
case 12:
|
||||
return "MOBILE_CBS";
|
||||
case 13:
|
||||
return "WIFI_P2P";
|
||||
default:
|
||||
return Integer.toString(type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@hide}
|
||||
*/
|
||||
public static boolean isNetworkTypeMobile(int networkType) {
|
||||
switch (networkType) {
|
||||
case 0:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(mType, mSubType, mSubscriberId, mNetworkId, mRoaming);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof NetworkIdentity) {
|
||||
final NetworkIdentity ident = (NetworkIdentity) obj;
|
||||
return mType == ident.mType && mSubType == ident.mSubType && mRoaming == ident.mRoaming
|
||||
&& Objects.equal(mSubscriberId, ident.mSubscriberId)
|
||||
&& Objects.equal(mNetworkId, ident.mNetworkId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder("[");
|
||||
builder.append("type=").append(getNetworkTypeName(mType));
|
||||
builder.append(", subType=");
|
||||
if (COMBINE_SUBTYPE_ENABLED) {
|
||||
builder.append("COMBINED");
|
||||
} else if (isNetworkTypeMobile(mType)) {
|
||||
builder.append(getNetworkTypeName(mSubType));
|
||||
} else {
|
||||
builder.append(mSubType);
|
||||
}
|
||||
if (mSubscriberId != null) {
|
||||
builder.append(", subscriberId=").append(scrubSubscriberId(mSubscriberId));
|
||||
}
|
||||
if (mNetworkId != null) {
|
||||
builder.append(", networkId=").append(mNetworkId);
|
||||
}
|
||||
if (mRoaming) {
|
||||
builder.append(", ROAMING");
|
||||
}
|
||||
return builder.append("]").toString();
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return mType;
|
||||
}
|
||||
|
||||
public int getSubType() {
|
||||
return mSubType;
|
||||
}
|
||||
|
||||
public String getSubscriberId() {
|
||||
return mSubscriberId;
|
||||
}
|
||||
|
||||
public String getNetworkId() {
|
||||
return mNetworkId;
|
||||
}
|
||||
|
||||
public boolean getRoaming() {
|
||||
return mRoaming;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrub given IMSI on production builds.
|
||||
*/
|
||||
public static String scrubSubscriberId(String subscriberId) {
|
||||
if ("eng".equals(Build.TYPE)) {
|
||||
return subscriberId;
|
||||
} else if (subscriberId != null) {
|
||||
// TODO: parse this as MCC+MNC instead of hard-coding
|
||||
return subscriberId.substring(0, Math.min(6, subscriberId.length())) + "...";
|
||||
} else {
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a {@link NetworkIdentity} from the given {@link NetworkState},
|
||||
* assuming that any mobile networks are using the current IMSI.
|
||||
*/
|
||||
public static NetworkIdentity buildNetworkIdentity(Context context, NetworkState state) {
|
||||
final int type = state.networkInfo.getType();
|
||||
final int subType = state.networkInfo.getSubtype();
|
||||
|
||||
// TODO: consider moving subscriberId over to LinkCapabilities, so it
|
||||
// comes from an authoritative source.
|
||||
|
||||
String subscriberId = null;
|
||||
String networkId = null;
|
||||
boolean roaming = false;
|
||||
|
||||
if (isNetworkTypeMobile(type)) {
|
||||
final TelephonyManager telephony = (TelephonyManager) context.getSystemService(
|
||||
Context.TELEPHONY_SERVICE);
|
||||
roaming = telephony.isNetworkRoaming();
|
||||
if (state.subscriberId != null) {
|
||||
subscriberId = state.subscriberId;
|
||||
} else {
|
||||
subscriberId = telephony.getSubscriberId();
|
||||
}
|
||||
|
||||
} else if (type == TYPE_WIFI) {
|
||||
if (state.networkId != null) {
|
||||
networkId = state.networkId;
|
||||
} else {
|
||||
final WifiManager wifi = (WifiManager) context.getSystemService(
|
||||
Context.WIFI_SERVICE);
|
||||
final WifiInfo info = wifi.getConnectionInfo();
|
||||
networkId = info != null ? info.getSSID() : null;
|
||||
}
|
||||
}
|
||||
|
||||
return new NetworkIdentity(type, subType, subscriberId, networkId, roaming);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* 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 android.net;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import com.android.internal.util.Objects;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Policy for networks matching a {@link NetworkTemplate}, including usage cycle
|
||||
* and limits to be enforced.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
|
||||
public static final int CYCLE_NONE = -1;
|
||||
public static final long WARNING_DISABLED = -1;
|
||||
public static final long LIMIT_DISABLED = -1;
|
||||
public static final long SNOOZE_NEVER = -1;
|
||||
|
||||
public final NetworkTemplate template;
|
||||
public int cycleDay;
|
||||
public String cycleTimezone;
|
||||
public long warningBytes;
|
||||
public long limitBytes;
|
||||
public long lastWarningSnooze;
|
||||
public long lastLimitSnooze;
|
||||
public boolean metered;
|
||||
public boolean inferred;
|
||||
|
||||
private static final long DEFAULT_MTU = 1500;
|
||||
|
||||
@Deprecated
|
||||
public NetworkPolicy(NetworkTemplate template, int cycleDay, String cycleTimezone,
|
||||
long warningBytes, long limitBytes, boolean metered) {
|
||||
this(template, cycleDay, cycleTimezone, warningBytes, limitBytes, SNOOZE_NEVER,
|
||||
SNOOZE_NEVER, metered, false);
|
||||
}
|
||||
|
||||
public NetworkPolicy(NetworkTemplate template, int cycleDay, String cycleTimezone,
|
||||
long warningBytes, long limitBytes, long lastWarningSnooze, long lastLimitSnooze,
|
||||
boolean metered, boolean inferred) {
|
||||
this.template = checkNotNull(template, "missing NetworkTemplate");
|
||||
this.cycleDay = cycleDay;
|
||||
this.cycleTimezone = checkNotNull(cycleTimezone, "missing cycleTimezone");
|
||||
this.warningBytes = warningBytes;
|
||||
this.limitBytes = limitBytes;
|
||||
this.lastWarningSnooze = lastWarningSnooze;
|
||||
this.lastLimitSnooze = lastLimitSnooze;
|
||||
this.metered = metered;
|
||||
this.inferred = inferred;
|
||||
}
|
||||
|
||||
public NetworkPolicy(Parcel in) {
|
||||
template = in.readParcelable(null);
|
||||
cycleDay = in.readInt();
|
||||
cycleTimezone = in.readString();
|
||||
warningBytes = in.readLong();
|
||||
limitBytes = in.readLong();
|
||||
lastWarningSnooze = in.readLong();
|
||||
lastLimitSnooze = in.readLong();
|
||||
metered = in.readInt() != 0;
|
||||
inferred = in.readInt() != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeParcelable(template, flags);
|
||||
dest.writeInt(cycleDay);
|
||||
dest.writeString(cycleTimezone);
|
||||
dest.writeLong(warningBytes);
|
||||
dest.writeLong(limitBytes);
|
||||
dest.writeLong(lastWarningSnooze);
|
||||
dest.writeLong(lastLimitSnooze);
|
||||
dest.writeInt(metered ? 1 : 0);
|
||||
dest.writeInt(inferred ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if given measurement is over {@link #warningBytes}.
|
||||
*/
|
||||
public boolean isOverWarning(long totalBytes) {
|
||||
return warningBytes != WARNING_DISABLED && totalBytes >= warningBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if given measurement is near enough to {@link #limitBytes} to be
|
||||
* considered over-limit.
|
||||
*/
|
||||
public boolean isOverLimit(long totalBytes) {
|
||||
// over-estimate, since kernel will trigger limit once first packet
|
||||
// trips over limit.
|
||||
totalBytes += 2 * DEFAULT_MTU;
|
||||
return limitBytes != LIMIT_DISABLED && totalBytes >= limitBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear any existing snooze values, setting to {@link #SNOOZE_NEVER}.
|
||||
*/
|
||||
public void clearSnooze() {
|
||||
lastWarningSnooze = SNOOZE_NEVER;
|
||||
lastLimitSnooze = SNOOZE_NEVER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if this policy has a cycle defined, after which usage should reset.
|
||||
*/
|
||||
public boolean hasCycle() {
|
||||
return cycleDay != CYCLE_NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(NetworkPolicy another) {
|
||||
if (another == null || another.limitBytes == LIMIT_DISABLED) {
|
||||
// other value is missing or disabled; we win
|
||||
return -1;
|
||||
}
|
||||
if (limitBytes == LIMIT_DISABLED || another.limitBytes < limitBytes) {
|
||||
// we're disabled or other limit is smaller; they win
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(template, cycleDay, cycleTimezone, warningBytes, limitBytes,
|
||||
lastWarningSnooze, lastLimitSnooze, metered, inferred);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof NetworkPolicy) {
|
||||
final NetworkPolicy other = (NetworkPolicy) obj;
|
||||
return cycleDay == other.cycleDay && warningBytes == other.warningBytes
|
||||
&& limitBytes == other.limitBytes
|
||||
&& lastWarningSnooze == other.lastWarningSnooze
|
||||
&& lastLimitSnooze == other.lastLimitSnooze && metered == other.metered
|
||||
&& inferred == other.inferred
|
||||
&& Objects.equal(cycleTimezone, other.cycleTimezone)
|
||||
&& Objects.equal(template, other.template);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder("NetworkPolicy");
|
||||
builder.append("[").append(template).append("]:");
|
||||
builder.append(" cycleDay=").append(cycleDay);
|
||||
builder.append(", cycleTimezone=").append(cycleTimezone);
|
||||
builder.append(", warningBytes=").append(warningBytes);
|
||||
builder.append(", limitBytes=").append(limitBytes);
|
||||
builder.append(", lastWarningSnooze=").append(lastWarningSnooze);
|
||||
builder.append(", lastLimitSnooze=").append(lastLimitSnooze);
|
||||
builder.append(", metered=").append(metered);
|
||||
builder.append(", inferred=").append(inferred);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static final Creator<NetworkPolicy> CREATOR = new Creator<NetworkPolicy>() {
|
||||
@Override
|
||||
public NetworkPolicy createFromParcel(Parcel in) {
|
||||
return new NetworkPolicy(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkPolicy[] newArray(int size) {
|
||||
return new NetworkPolicy[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
* 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 android.net;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.Signature;
|
||||
import android.os.RemoteException;
|
||||
import android.text.format.Time;
|
||||
import com.google.android.collect.Sets;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static android.content.pm.PackageManager.GET_SIGNATURES;
|
||||
import static android.net.NetworkPolicy.CYCLE_NONE;
|
||||
import static android.text.format.Time.MONTH_DAY;
|
||||
|
||||
/**
|
||||
* Manager for creating and modifying network policy rules.
|
||||
* <p/>
|
||||
* {@hide}
|
||||
*/
|
||||
public class NetworkPolicyManager {
|
||||
|
||||
/**
|
||||
* No specific network policy, use system default.
|
||||
*/
|
||||
public static final int POLICY_NONE = 0x0;
|
||||
/**
|
||||
* Reject network usage on metered networks when application in background.
|
||||
*/
|
||||
public static final int POLICY_REJECT_METERED_BACKGROUND = 0x1;
|
||||
|
||||
/**
|
||||
* All network traffic should be allowed.
|
||||
*/
|
||||
public static final int RULE_ALLOW_ALL = 0x0;
|
||||
/**
|
||||
* Reject traffic on metered networks.
|
||||
*/
|
||||
public static final int RULE_REJECT_METERED = 0x1;
|
||||
|
||||
private static final boolean ALLOW_PLATFORM_APP_POLICY = true;
|
||||
|
||||
/**
|
||||
* {@link Intent} extra that indicates which {@link NetworkTemplate} rule it
|
||||
* applies to.
|
||||
*/
|
||||
public static final String EXTRA_NETWORK_TEMPLATE = "android.net.NETWORK_TEMPLATE";
|
||||
|
||||
private INetworkPolicyManager mService;
|
||||
|
||||
public NetworkPolicyManager(INetworkPolicyManager service) {
|
||||
if (service == null) {
|
||||
throw new IllegalArgumentException("missing INetworkPolicyManager");
|
||||
}
|
||||
mService = service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set policy flags for specific UID.
|
||||
*
|
||||
* @param policy {@link #POLICY_NONE} or combination of flags like
|
||||
* {@link #POLICY_REJECT_METERED_BACKGROUND}.
|
||||
*/
|
||||
public void setUidPolicy(int uid, int policy) {
|
||||
try {
|
||||
mService.setUidPolicy(uid, policy);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public int getUidPolicy(int uid) {
|
||||
try {
|
||||
return mService.getUidPolicy(uid);
|
||||
} catch (RemoteException e) {
|
||||
return POLICY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
public int[] getUidsWithPolicy(int policy) {
|
||||
try {
|
||||
return mService.getUidsWithPolicy(policy);
|
||||
} catch (RemoteException e) {
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
public void registerListener(INetworkPolicyListener listener) {
|
||||
try {
|
||||
mService.registerListener(listener);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterListener(INetworkPolicyListener listener) {
|
||||
try {
|
||||
mService.unregisterListener(listener);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void setNetworkPolicies(NetworkPolicy[] policies) {
|
||||
try {
|
||||
mService.setNetworkPolicies(policies);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public NetworkPolicy[] getNetworkPolicies() {
|
||||
try {
|
||||
return mService.getNetworkPolicies();
|
||||
} catch (RemoteException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setRestrictBackground(boolean restrictBackground) {
|
||||
try {
|
||||
mService.setRestrictBackground(restrictBackground);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getRestrictBackground() {
|
||||
try {
|
||||
return mService.getRestrictBackground();
|
||||
} catch (RemoteException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the last cycle boundary for the given {@link NetworkPolicy}. For
|
||||
* example, if cycle day is 20th, and today is June 15th, it will return May
|
||||
* 20th. When cycle day doesn't exist in current month, it snaps to the 1st
|
||||
* of following month.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static long computeLastCycleBoundary(long currentTime, NetworkPolicy policy) {
|
||||
if (policy.cycleDay == CYCLE_NONE) {
|
||||
throw new IllegalArgumentException("Unable to compute boundary without cycleDay");
|
||||
}
|
||||
|
||||
final Time now = new Time(policy.cycleTimezone);
|
||||
now.set(currentTime);
|
||||
|
||||
// first, find cycle boundary for current month
|
||||
final Time cycle = new Time(now);
|
||||
cycle.hour = cycle.minute = cycle.second = 0;
|
||||
snapToCycleDay(cycle, policy.cycleDay);
|
||||
|
||||
if (Time.compare(cycle, now) >= 0) {
|
||||
// cycle boundary is beyond now, use last cycle boundary; start by
|
||||
// pushing ourselves squarely into last month.
|
||||
final Time lastMonth = new Time(now);
|
||||
lastMonth.hour = lastMonth.minute = lastMonth.second = 0;
|
||||
lastMonth.monthDay = 1;
|
||||
lastMonth.month -= 1;
|
||||
lastMonth.normalize(true);
|
||||
|
||||
cycle.set(lastMonth);
|
||||
snapToCycleDay(cycle, policy.cycleDay);
|
||||
}
|
||||
|
||||
return cycle.toMillis(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@hide}
|
||||
*/
|
||||
public static long computeNextCycleBoundary(long currentTime, NetworkPolicy policy) {
|
||||
if (policy.cycleDay == CYCLE_NONE) {
|
||||
throw new IllegalArgumentException("Unable to compute boundary without cycleDay");
|
||||
}
|
||||
|
||||
final Time now = new Time(policy.cycleTimezone);
|
||||
now.set(currentTime);
|
||||
|
||||
// first, find cycle boundary for current month
|
||||
final Time cycle = new Time(now);
|
||||
cycle.hour = cycle.minute = cycle.second = 0;
|
||||
snapToCycleDay(cycle, policy.cycleDay);
|
||||
|
||||
if (Time.compare(cycle, now) <= 0) {
|
||||
// cycle boundary is before now, use next cycle boundary; start by
|
||||
// pushing ourselves squarely into next month.
|
||||
final Time nextMonth = new Time(now);
|
||||
nextMonth.hour = nextMonth.minute = nextMonth.second = 0;
|
||||
nextMonth.monthDay = 1;
|
||||
nextMonth.month += 1;
|
||||
nextMonth.normalize(true);
|
||||
|
||||
cycle.set(nextMonth);
|
||||
snapToCycleDay(cycle, policy.cycleDay);
|
||||
}
|
||||
|
||||
return cycle.toMillis(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Snap to the cycle day for the current month given; when cycle day doesn't
|
||||
* exist, it snaps to last second of current month.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static void snapToCycleDay(Time time, int cycleDay) {
|
||||
if (cycleDay > time.getActualMaximum(MONTH_DAY)) {
|
||||
// cycle day isn't valid this month; snap to last second of month
|
||||
time.month += 1;
|
||||
time.monthDay = 1;
|
||||
time.second = -1;
|
||||
} else {
|
||||
time.monthDay = cycleDay;
|
||||
}
|
||||
time.normalize(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if given UID can have a {@link #setUidPolicy(int, int)} defined,
|
||||
* usually to protect critical system services.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isUidValidForPolicy(Context context, int uid) {
|
||||
|
||||
if (!ALLOW_PLATFORM_APP_POLICY) {
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
final HashSet<Signature> systemSignature;
|
||||
try {
|
||||
systemSignature = Sets.newHashSet(
|
||||
pm.getPackageInfo("android", GET_SIGNATURES).signatures);
|
||||
} catch (NameNotFoundException e) {
|
||||
throw new RuntimeException("problem finding system signature", e);
|
||||
}
|
||||
|
||||
try {
|
||||
// reject apps signed with platform cert
|
||||
for (String packageName : pm.getPackagesForUid(uid)) {
|
||||
final HashSet<Signature> packageSignature = Sets.newHashSet(
|
||||
pm.getPackageInfo(packageName, GET_SIGNATURES).signatures);
|
||||
if (packageSignature.containsAll(systemSignature)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
}
|
||||
}
|
||||
|
||||
// nothing found above; we can apply policy to UID
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@hide}
|
||||
*/
|
||||
public static void dumpPolicy(PrintWriter fout, int policy) {
|
||||
fout.write("[");
|
||||
if ((policy & POLICY_REJECT_METERED_BACKGROUND) != 0) {
|
||||
fout.write("REJECT_METERED_BACKGROUND");
|
||||
}
|
||||
fout.write("]");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@hide}
|
||||
*/
|
||||
public static void dumpRules(PrintWriter fout, int rules) {
|
||||
fout.write("[");
|
||||
if ((rules & RULE_REJECT_METERED) != 0) {
|
||||
fout.write("REJECT_METERED");
|
||||
}
|
||||
fout.write("]");
|
||||
}
|
||||
|
||||
}
|
||||
Executable → Regular
Executable → Regular
@@ -0,0 +1,453 @@
|
||||
/*
|
||||
* 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 android.net;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.Objects;
|
||||
|
||||
import static android.net.ConnectivityManager.*;
|
||||
import static android.net.NetworkIdentity.COMBINE_SUBTYPE_ENABLED;
|
||||
import static android.net.NetworkIdentity.scrubSubscriberId;
|
||||
import static com.android.internal.util.ArrayUtils.contains;
|
||||
|
||||
/**
|
||||
* Template definition used to generically match {@link NetworkIdentity},
|
||||
* usually when collecting statistics.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public class NetworkTemplate implements Parcelable {
|
||||
|
||||
public static final int MATCH_MOBILE_ALL = 1;
|
||||
public static final int MATCH_MOBILE_3G_LOWER = 2;
|
||||
public static final int MATCH_MOBILE_4G = 3;
|
||||
public static final int MATCH_WIFI = 4;
|
||||
public static final int MATCH_ETHERNET = 5;
|
||||
public static final int MATCH_MOBILE_WILDCARD = 6;
|
||||
public static final int MATCH_WIFI_WILDCARD = 7;
|
||||
|
||||
/**
|
||||
* Network type is unknown
|
||||
*/
|
||||
public static final int NETWORK_TYPE_UNKNOWN = 0;
|
||||
/**
|
||||
* Current network is GPRS
|
||||
*/
|
||||
public static final int NETWORK_TYPE_GPRS = 1;
|
||||
/**
|
||||
* Current network is EDGE
|
||||
*/
|
||||
public static final int NETWORK_TYPE_EDGE = 2;
|
||||
/**
|
||||
* Current network is UMTS
|
||||
*/
|
||||
public static final int NETWORK_TYPE_UMTS = 3;
|
||||
/**
|
||||
* Current network is CDMA: Either IS95A or IS95B
|
||||
*/
|
||||
public static final int NETWORK_TYPE_CDMA = 4;
|
||||
/**
|
||||
* Current network is EVDO revision 0
|
||||
*/
|
||||
public static final int NETWORK_TYPE_EVDO_0 = 5;
|
||||
/**
|
||||
* Current network is EVDO revision A
|
||||
*/
|
||||
public static final int NETWORK_TYPE_EVDO_A = 6;
|
||||
/**
|
||||
* Current network is 1xRTT
|
||||
*/
|
||||
public static final int NETWORK_TYPE_1xRTT = 7;
|
||||
/**
|
||||
* Current network is HSDPA
|
||||
*/
|
||||
public static final int NETWORK_TYPE_HSDPA = 8;
|
||||
/**
|
||||
* Current network is HSUPA
|
||||
*/
|
||||
public static final int NETWORK_TYPE_HSUPA = 9;
|
||||
/**
|
||||
* Current network is HSPA
|
||||
*/
|
||||
public static final int NETWORK_TYPE_HSPA = 10;
|
||||
/**
|
||||
* Current network is iDen
|
||||
*/
|
||||
public static final int NETWORK_TYPE_IDEN = 11;
|
||||
/**
|
||||
* Current network is EVDO revision B
|
||||
*/
|
||||
public static final int NETWORK_TYPE_EVDO_B = 12;
|
||||
/**
|
||||
* Current network is LTE
|
||||
*/
|
||||
public static final int NETWORK_TYPE_LTE = 13;
|
||||
/**
|
||||
* Current network is eHRPD
|
||||
*/
|
||||
public static final int NETWORK_TYPE_EHRPD = 14;
|
||||
/**
|
||||
* Current network is HSPA+
|
||||
*/
|
||||
public static final int NETWORK_TYPE_HSPAP = 15;
|
||||
|
||||
/**
|
||||
* Unknown network class. {@hide}
|
||||
*/
|
||||
public static final int NETWORK_CLASS_UNKNOWN = 0;
|
||||
/**
|
||||
* Class of broadly defined "2G" networks. {@hide}
|
||||
*/
|
||||
public static final int NETWORK_CLASS_2_G = 1;
|
||||
/**
|
||||
* Class of broadly defined "3G" networks. {@hide}
|
||||
*/
|
||||
public static final int NETWORK_CLASS_3_G = 2;
|
||||
/**
|
||||
* Class of broadly defined "4G" networks. {@hide}
|
||||
*/
|
||||
public static final int NETWORK_CLASS_4_G = 3;
|
||||
|
||||
/**
|
||||
* Return general class of network type, such as "3G" or "4G". In cases
|
||||
* where classification is contentious, this method is conservative.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static int getNetworkClass(int networkType) {
|
||||
switch (networkType) {
|
||||
case NETWORK_TYPE_GPRS:
|
||||
case NETWORK_TYPE_EDGE:
|
||||
case NETWORK_TYPE_CDMA:
|
||||
case NETWORK_TYPE_1xRTT:
|
||||
case NETWORK_TYPE_IDEN:
|
||||
return NETWORK_CLASS_2_G;
|
||||
case NETWORK_TYPE_UMTS:
|
||||
case NETWORK_TYPE_EVDO_0:
|
||||
case NETWORK_TYPE_EVDO_A:
|
||||
case NETWORK_TYPE_HSDPA:
|
||||
case NETWORK_TYPE_HSUPA:
|
||||
case NETWORK_TYPE_HSPA:
|
||||
case NETWORK_TYPE_EVDO_B:
|
||||
case NETWORK_TYPE_EHRPD:
|
||||
case NETWORK_TYPE_HSPAP:
|
||||
return NETWORK_CLASS_3_G;
|
||||
case NETWORK_TYPE_LTE:
|
||||
return NETWORK_CLASS_4_G;
|
||||
default:
|
||||
return NETWORK_CLASS_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set of {@link NetworkInfo#getType()} that reflect data usage.
|
||||
*/
|
||||
private static final int[] DATA_USAGE_NETWORK_TYPES = {0};
|
||||
|
||||
private static boolean sForceAllNetworkTypes = false;
|
||||
|
||||
@VisibleForTesting
|
||||
public static void forceAllNetworkTypes() {
|
||||
sForceAllNetworkTypes = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
|
||||
* the given IMSI.
|
||||
*/
|
||||
public static NetworkTemplate buildTemplateMobileAll(String subscriberId) {
|
||||
return new NetworkTemplate(MATCH_MOBILE_ALL, subscriberId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
|
||||
* the given IMSI that roughly meet a "3G" definition, or lower.
|
||||
*/
|
||||
@Deprecated
|
||||
public static NetworkTemplate buildTemplateMobile3gLower(String subscriberId) {
|
||||
return new NetworkTemplate(MATCH_MOBILE_3G_LOWER, subscriberId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
|
||||
* the given IMSI that roughly meet a "4G" definition.
|
||||
*/
|
||||
@Deprecated
|
||||
public static NetworkTemplate buildTemplateMobile4g(String subscriberId) {
|
||||
return new NetworkTemplate(MATCH_MOBILE_4G, subscriberId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to match {@link ConnectivityManager#TYPE_MOBILE} networks,
|
||||
* regardless of IMSI.
|
||||
*/
|
||||
public static NetworkTemplate buildTemplateMobileWildcard() {
|
||||
return new NetworkTemplate(MATCH_MOBILE_WILDCARD, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to match all {@link ConnectivityManager#TYPE_WIFI} networks,
|
||||
* regardless of SSID.
|
||||
*/
|
||||
public static NetworkTemplate buildTemplateWifiWildcard() {
|
||||
return new NetworkTemplate(MATCH_WIFI_WILDCARD, null, null);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static NetworkTemplate buildTemplateWifi() {
|
||||
return buildTemplateWifiWildcard();
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to match {@link ConnectivityManager#TYPE_WIFI} networks with the
|
||||
* given SSID.
|
||||
*/
|
||||
public static NetworkTemplate buildTemplateWifi(String networkId) {
|
||||
return new NetworkTemplate(MATCH_WIFI, null, networkId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to combine all {@link ConnectivityManager#TYPE_ETHERNET} style
|
||||
* networks together.
|
||||
*/
|
||||
public static NetworkTemplate buildTemplateEthernet() {
|
||||
return new NetworkTemplate(MATCH_ETHERNET, null, null);
|
||||
}
|
||||
|
||||
private final int mMatchRule;
|
||||
private final String mSubscriberId;
|
||||
private final String mNetworkId;
|
||||
|
||||
public NetworkTemplate(int matchRule, String subscriberId, String networkId) {
|
||||
mMatchRule = matchRule;
|
||||
mSubscriberId = subscriberId;
|
||||
mNetworkId = networkId;
|
||||
}
|
||||
|
||||
private NetworkTemplate(Parcel in) {
|
||||
mMatchRule = in.readInt();
|
||||
mSubscriberId = in.readString();
|
||||
mNetworkId = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(mMatchRule);
|
||||
dest.writeString(mSubscriberId);
|
||||
dest.writeString(mNetworkId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder("NetworkTemplate: ");
|
||||
builder.append("matchRule=").append(getMatchRuleName(mMatchRule));
|
||||
if (mSubscriberId != null) {
|
||||
builder.append(", subscriberId=").append(scrubSubscriberId(mSubscriberId));
|
||||
}
|
||||
if (mNetworkId != null) {
|
||||
builder.append(", networkId=").append(mNetworkId);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(mMatchRule, mSubscriberId, mNetworkId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof NetworkTemplate) {
|
||||
final NetworkTemplate other = (NetworkTemplate) obj;
|
||||
return mMatchRule == other.mMatchRule
|
||||
&& Objects.equal(mSubscriberId, other.mSubscriberId)
|
||||
&& Objects.equal(mNetworkId, other.mNetworkId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getMatchRule() {
|
||||
return mMatchRule;
|
||||
}
|
||||
|
||||
public String getSubscriberId() {
|
||||
return mSubscriberId;
|
||||
}
|
||||
|
||||
public String getNetworkId() {
|
||||
return mNetworkId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if given {@link NetworkIdentity} matches this template.
|
||||
*/
|
||||
public boolean matches(NetworkIdentity ident) {
|
||||
switch (mMatchRule) {
|
||||
case MATCH_MOBILE_ALL:
|
||||
return matchesMobile(ident);
|
||||
case MATCH_MOBILE_3G_LOWER:
|
||||
return matchesMobile3gLower(ident);
|
||||
case MATCH_MOBILE_4G:
|
||||
return matchesMobile4g(ident);
|
||||
case MATCH_WIFI:
|
||||
return matchesWifi(ident);
|
||||
case MATCH_ETHERNET:
|
||||
return matchesEthernet(ident);
|
||||
case MATCH_MOBILE_WILDCARD:
|
||||
return matchesMobileWildcard(ident);
|
||||
case MATCH_WIFI_WILDCARD:
|
||||
return matchesWifiWildcard(ident);
|
||||
default:
|
||||
throw new IllegalArgumentException("unknown network template");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mobile network with matching IMSI.
|
||||
*/
|
||||
private boolean matchesMobile(NetworkIdentity ident) {
|
||||
if (ident.mType == TYPE_WIMAX) {
|
||||
// TODO: consider matching against WiMAX subscriber identity
|
||||
return true;
|
||||
} else {
|
||||
return ((sForceAllNetworkTypes || contains(DATA_USAGE_NETWORK_TYPES, ident.mType))
|
||||
&& Objects.equal(mSubscriberId, ident.mSubscriberId));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mobile network classified 3G or lower with matching IMSI.
|
||||
*/
|
||||
private boolean matchesMobile3gLower(NetworkIdentity ident) {
|
||||
ensureSubtypeAvailable();
|
||||
if (ident.mType == TYPE_WIMAX) {
|
||||
return false;
|
||||
} else if (matchesMobile(ident)) {
|
||||
switch (getNetworkClass(ident.mSubType)) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mobile network classified 4G with matching IMSI.
|
||||
*/
|
||||
private boolean matchesMobile4g(NetworkIdentity ident) {
|
||||
ensureSubtypeAvailable();
|
||||
if (ident.mType == TYPE_WIMAX) {
|
||||
// TODO: consider matching against WiMAX subscriber identity
|
||||
return true;
|
||||
} else if (matchesMobile(ident)) {
|
||||
switch (getNetworkClass(ident.mSubType)) {
|
||||
case 3:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if matches Wi-Fi network template.
|
||||
*/
|
||||
private boolean matchesWifi(NetworkIdentity ident) {
|
||||
switch (ident.mType) {
|
||||
case TYPE_WIFI:
|
||||
return Objects.equal(mNetworkId, ident.mNetworkId);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if matches Ethernet network template.
|
||||
*/
|
||||
private boolean matchesEthernet(NetworkIdentity ident) {
|
||||
if (ident.mType == TYPE_ETHERNET) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean matchesMobileWildcard(NetworkIdentity ident) {
|
||||
if (ident.mType == TYPE_WIMAX) {
|
||||
return true;
|
||||
} else {
|
||||
return sForceAllNetworkTypes || contains(DATA_USAGE_NETWORK_TYPES, ident.mType);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean matchesWifiWildcard(NetworkIdentity ident) {
|
||||
switch (ident.mType) {
|
||||
case TYPE_WIFI:
|
||||
case 13:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getMatchRuleName(int matchRule) {
|
||||
switch (matchRule) {
|
||||
case MATCH_MOBILE_3G_LOWER:
|
||||
return "MOBILE_3G_LOWER";
|
||||
case MATCH_MOBILE_4G:
|
||||
return "MOBILE_4G";
|
||||
case MATCH_MOBILE_ALL:
|
||||
return "MOBILE_ALL";
|
||||
case MATCH_WIFI:
|
||||
return "WIFI";
|
||||
case MATCH_ETHERNET:
|
||||
return "ETHERNET";
|
||||
case MATCH_MOBILE_WILDCARD:
|
||||
return "MOBILE_WILDCARD";
|
||||
case MATCH_WIFI_WILDCARD:
|
||||
return "WIFI_WILDCARD";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
private static void ensureSubtypeAvailable() {
|
||||
if (COMBINE_SUBTYPE_ENABLED) {
|
||||
throw new IllegalArgumentException(
|
||||
"Unable to enforce 3G_LOWER template on combined data.");
|
||||
}
|
||||
}
|
||||
|
||||
public static final Creator<NetworkTemplate> CREATOR = new Creator<NetworkTemplate>() {
|
||||
@Override
|
||||
public NetworkTemplate createFromParcel(Parcel in) {
|
||||
return new NetworkTemplate(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkTemplate[] newArray(int size) {
|
||||
return new NetworkTemplate[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
Executable → Regular
+4
-2
@@ -16,7 +16,7 @@
|
||||
|
||||
package android.net;
|
||||
|
||||
import timber.log.Timber;
|
||||
import timber.log.Timber; import android.util.Log; import static com.klinker.android.timberworkarounds.TimberExtensionsKt.Timber_isLoggable; // inserted with sed
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
@@ -31,6 +31,8 @@ import java.util.Collection;
|
||||
*/
|
||||
public class NetworkUtilsHelper {
|
||||
|
||||
private static final String TAG = "NetworkUtils";
|
||||
|
||||
/**
|
||||
* Bring the named network interface up.
|
||||
*/
|
||||
@@ -253,7 +255,7 @@ public class NetworkUtilsHelper {
|
||||
addrHexString.substring(16, 20), addrHexString.substring(20, 24),
|
||||
addrHexString.substring(24, 28), addrHexString.substring(28, 32)));
|
||||
} catch (Exception e) {
|
||||
Timber.e("error in hexToInet6Address(" + addrHexString + "): " + e);
|
||||
Log.e("NetworkUtils", "error in hexToInet6Address(" + addrHexString + "): " + e);
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
Executable → Regular
+6
-5
@@ -18,7 +18,7 @@ package android.net;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import timber.log.Timber;
|
||||
import timber.log.Timber; import android.util.Log; import static com.klinker.android.timberworkarounds.TimberExtensionsKt.Timber_isLoggable; // inserted with sed
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
@@ -32,6 +32,7 @@ import java.util.Collection;
|
||||
* @hide
|
||||
*/
|
||||
public class RouteInfo implements Parcelable {
|
||||
private static final String TAG = "RouteInfo";
|
||||
/**
|
||||
* The IP destination address for this route.
|
||||
*/
|
||||
@@ -53,14 +54,14 @@ public class RouteInfo implements Parcelable {
|
||||
destination = new LinkAddress(Inet4Address.getLocalHost(), 0);
|
||||
} catch (UnknownHostException e) {
|
||||
// TODO Auto-generated catch block
|
||||
Timber.e(e, "exception thrown");
|
||||
Log.e(TAG, "exception thrown", e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
destination = new LinkAddress(Inet6Address.getLocalHost(), 0);
|
||||
} catch (UnknownHostException e) {
|
||||
// TODO Auto-generated catch block
|
||||
Timber.e(e, "exception thrown");
|
||||
Log.e(TAG, "exception thrown", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -74,14 +75,14 @@ public class RouteInfo implements Parcelable {
|
||||
gateway = Inet4Address.getLocalHost();
|
||||
} catch (UnknownHostException e) {
|
||||
// TODO Auto-generated catch block
|
||||
Timber.e(e, "exception thrown");
|
||||
Log.e(TAG, "exception thrown", e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
gateway = Inet6Address.getLocalHost();
|
||||
} catch (UnknownHostException e) {
|
||||
// TODO Auto-generated catch block
|
||||
Timber.e(e, "exception thrown");
|
||||
Log.e(TAG, "exception thrown", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,835 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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 android.provider;
|
||||
|
||||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
import android.net.NetworkPolicyManager;
|
||||
import android.net.Uri;
|
||||
|
||||
/**
|
||||
* The Download Manager
|
||||
*
|
||||
* @pending
|
||||
*/
|
||||
public final class Downloads {
|
||||
private Downloads() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation details
|
||||
* <p/>
|
||||
* Exposes constants used to interact with the download manager's
|
||||
* content provider.
|
||||
* The constants URI ... STATUS are the names of columns in the downloads table.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final class Impl implements BaseColumns {
|
||||
private Impl() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The permission to access the download manager
|
||||
*/
|
||||
public static final String PERMISSION_ACCESS = "android.permission.ACCESS_DOWNLOAD_MANAGER";
|
||||
|
||||
/**
|
||||
* The permission to access the download manager's advanced functions
|
||||
*/
|
||||
public static final String PERMISSION_ACCESS_ADVANCED =
|
||||
"android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED";
|
||||
|
||||
/**
|
||||
* The permission to access the all the downloads in the manager.
|
||||
*/
|
||||
public static final String PERMISSION_ACCESS_ALL =
|
||||
"android.permission.ACCESS_ALL_DOWNLOADS";
|
||||
|
||||
/**
|
||||
* The permission to directly access the download manager's cache
|
||||
* directory
|
||||
*/
|
||||
public static final String PERMISSION_CACHE = "android.permission.ACCESS_CACHE_FILESYSTEM";
|
||||
|
||||
/**
|
||||
* The permission to send broadcasts on download completion
|
||||
*/
|
||||
public static final String PERMISSION_SEND_INTENTS =
|
||||
"android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS";
|
||||
|
||||
/**
|
||||
* The permission to download files to the cache partition that won't be automatically
|
||||
* purged when space is needed.
|
||||
*/
|
||||
public static final String PERMISSION_CACHE_NON_PURGEABLE =
|
||||
"android.permission.DOWNLOAD_CACHE_NON_PURGEABLE";
|
||||
|
||||
/**
|
||||
* The permission to download files without any system notification being shown.
|
||||
*/
|
||||
public static final String PERMISSION_NO_NOTIFICATION =
|
||||
"android.permission.DOWNLOAD_WITHOUT_NOTIFICATION";
|
||||
|
||||
/**
|
||||
* The content:// URI to access downloads owned by the caller's UID.
|
||||
*/
|
||||
public static final Uri CONTENT_URI =
|
||||
Uri.parse("content://downloads/my_downloads");
|
||||
|
||||
/**
|
||||
* The content URI for accessing all downloads across all UIDs (requires the
|
||||
* ACCESS_ALL_DOWNLOADS permission).
|
||||
*/
|
||||
public static final Uri ALL_DOWNLOADS_CONTENT_URI =
|
||||
Uri.parse("content://downloads/all_downloads");
|
||||
|
||||
/**
|
||||
* URI segment to access a publicly accessible downloaded file
|
||||
*/
|
||||
public static final String PUBLICLY_ACCESSIBLE_DOWNLOADS_URI_SEGMENT = "public_downloads";
|
||||
|
||||
/**
|
||||
* The content URI for accessing publicly accessible downloads (i.e., it requires no
|
||||
* permissions to access this downloaded file)
|
||||
*/
|
||||
public static final Uri PUBLICLY_ACCESSIBLE_DOWNLOADS_URI =
|
||||
Uri.parse("content://downloads/" + PUBLICLY_ACCESSIBLE_DOWNLOADS_URI_SEGMENT);
|
||||
|
||||
/**
|
||||
* Broadcast Action: this is sent by the download manager to the app
|
||||
* that had initiated a download when that download completes. The
|
||||
* download's content: uri is specified in the intent's data.
|
||||
*/
|
||||
public static final String ACTION_DOWNLOAD_COMPLETED =
|
||||
"android.intent.action.DOWNLOAD_COMPLETED";
|
||||
|
||||
/**
|
||||
* Broadcast Action: this is sent by the download manager to the app
|
||||
* that had initiated a download when the user selects the notification
|
||||
* associated with that download. The download's content: uri is specified
|
||||
* in the intent's data if the click is associated with a single download,
|
||||
* or Downloads.CONTENT_URI if the notification is associated with
|
||||
* multiple downloads.
|
||||
* Note: this is not currently sent for downloads that have completed
|
||||
* successfully.
|
||||
*/
|
||||
public static final String ACTION_NOTIFICATION_CLICKED =
|
||||
"android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED";
|
||||
|
||||
/**
|
||||
* The name of the column containing the URI of the data being downloaded.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Init/Read</P>
|
||||
*/
|
||||
public static final String COLUMN_URI = "uri";
|
||||
|
||||
/**
|
||||
* The name of the column containing application-specific data.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Init/Read/Write</P>
|
||||
*/
|
||||
public static final String COLUMN_APP_DATA = "entity";
|
||||
|
||||
/**
|
||||
* The name of the column containing the flags that indicates whether
|
||||
* the initiating application is capable of verifying the integrity of
|
||||
* the downloaded file. When this flag is set, the download manager
|
||||
* performs downloads and reports success even in some situations where
|
||||
* it can't guarantee that the download has completed (e.g. when doing
|
||||
* a byte-range request without an ETag, or when it can't determine
|
||||
* whether a download fully completed).
|
||||
* <P>Type: BOOLEAN</P>
|
||||
* <P>Owner can Init</P>
|
||||
*/
|
||||
public static final String COLUMN_NO_INTEGRITY = "no_integrity";
|
||||
|
||||
/**
|
||||
* The name of the column containing the filename that the initiating
|
||||
* application recommends. When possible, the download manager will attempt
|
||||
* to use this filename, or a variation, as the actual name for the file.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Init</P>
|
||||
*/
|
||||
public static final String COLUMN_FILE_NAME_HINT = "hint";
|
||||
|
||||
/**
|
||||
* The name of the column containing the filename where the downloaded data
|
||||
* was actually stored.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Read</P>
|
||||
*/
|
||||
public static final String _DATA = "_data";
|
||||
|
||||
/**
|
||||
* The name of the column containing the MIME type of the downloaded data.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Init/Read</P>
|
||||
*/
|
||||
public static final String COLUMN_MIME_TYPE = "mimetype";
|
||||
|
||||
/**
|
||||
* The name of the column containing the flag that controls the destination
|
||||
* of the download. See the DESTINATION_* constants for a list of legal values.
|
||||
* <P>Type: INTEGER</P>
|
||||
* <P>Owner can Init</P>
|
||||
*/
|
||||
public static final String COLUMN_DESTINATION = "destination";
|
||||
|
||||
/**
|
||||
* The name of the column containing the flags that controls whether the
|
||||
* download is displayed by the UI. See the VISIBILITY_* constants for
|
||||
* a list of legal values.
|
||||
* <P>Type: INTEGER</P>
|
||||
* <P>Owner can Init/Read/Write</P>
|
||||
*/
|
||||
public static final String COLUMN_VISIBILITY = "visibility";
|
||||
|
||||
/**
|
||||
* The name of the column containing the current control state of the download.
|
||||
* Applications can write to this to control (pause/resume) the download.
|
||||
* the CONTROL_* constants for a list of legal values.
|
||||
* <P>Type: INTEGER</P>
|
||||
* <P>Owner can Read</P>
|
||||
*/
|
||||
public static final String COLUMN_CONTROL = "control";
|
||||
|
||||
/**
|
||||
* The name of the column containing the current status of the download.
|
||||
* Applications can read this to follow the progress of each download. See
|
||||
* the STATUS_* constants for a list of legal values.
|
||||
* <P>Type: INTEGER</P>
|
||||
* <P>Owner can Read</P>
|
||||
*/
|
||||
public static final String COLUMN_STATUS = "status";
|
||||
|
||||
/**
|
||||
* The name of the column containing the date at which some interesting
|
||||
* status changed in the download. Stored as a System.currentTimeMillis()
|
||||
* value.
|
||||
* <P>Type: BIGINT</P>
|
||||
* <P>Owner can Read</P>
|
||||
*/
|
||||
public static final String COLUMN_LAST_MODIFICATION = "lastmod";
|
||||
|
||||
/**
|
||||
* The name of the column containing the package name of the application
|
||||
* that initiating the download. The download manager will send
|
||||
* notifications to a component in this package when the download completes.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Init/Read</P>
|
||||
*/
|
||||
public static final String COLUMN_NOTIFICATION_PACKAGE = "notificationpackage";
|
||||
|
||||
/**
|
||||
* The name of the column containing the component name of the class that
|
||||
* will receive notifications associated with the download. The
|
||||
* package/class combination is passed to
|
||||
* Intent.setClassName(String,String).
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Init/Read</P>
|
||||
*/
|
||||
public static final String COLUMN_NOTIFICATION_CLASS = "notificationclass";
|
||||
|
||||
/**
|
||||
* If extras are specified when requesting a download they will be provided in the intent that
|
||||
* is sent to the specified class and package when a download has finished.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Init</P>
|
||||
*/
|
||||
public static final String COLUMN_NOTIFICATION_EXTRAS = "notificationextras";
|
||||
|
||||
/**
|
||||
* The name of the column contain the values of the cookie to be used for
|
||||
* the download. This is used directly as the value for the Cookie: HTTP
|
||||
* header that gets sent with the request.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Init</P>
|
||||
*/
|
||||
public static final String COLUMN_COOKIE_DATA = "cookiedata";
|
||||
|
||||
/**
|
||||
* The name of the column containing the user agent that the initiating
|
||||
* application wants the download manager to use for this download.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Init</P>
|
||||
*/
|
||||
public static final String COLUMN_USER_AGENT = "useragent";
|
||||
|
||||
/**
|
||||
* The name of the column containing the referer (sic) that the initiating
|
||||
* application wants the download manager to use for this download.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Init</P>
|
||||
*/
|
||||
public static final String COLUMN_REFERER = "referer";
|
||||
|
||||
/**
|
||||
* The name of the column containing the total size of the file being
|
||||
* downloaded.
|
||||
* <P>Type: INTEGER</P>
|
||||
* <P>Owner can Read</P>
|
||||
*/
|
||||
public static final String COLUMN_TOTAL_BYTES = "total_bytes";
|
||||
|
||||
/**
|
||||
* The name of the column containing the size of the part of the file that
|
||||
* has been downloaded so far.
|
||||
* <P>Type: INTEGER</P>
|
||||
* <P>Owner can Read</P>
|
||||
*/
|
||||
public static final String COLUMN_CURRENT_BYTES = "current_bytes";
|
||||
|
||||
/**
|
||||
* The name of the column where the initiating application can provide the
|
||||
* UID of another application that is allowed to access this download. If
|
||||
* multiple applications share the same UID, all those applications will be
|
||||
* allowed to access this download. This column can be updated after the
|
||||
* download is initiated. This requires the permission
|
||||
* android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED.
|
||||
* <P>Type: INTEGER</P>
|
||||
* <P>Owner can Init</P>
|
||||
*/
|
||||
public static final String COLUMN_OTHER_UID = "otheruid";
|
||||
|
||||
/**
|
||||
* The name of the column where the initiating application can provided the
|
||||
* title of this download. The title will be displayed ito the user in the
|
||||
* list of downloads.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Init/Read/Write</P>
|
||||
*/
|
||||
public static final String COLUMN_TITLE = "title";
|
||||
|
||||
/**
|
||||
* The name of the column where the initiating application can provide the
|
||||
* description of this download. The description will be displayed to the
|
||||
* user in the list of downloads.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Init/Read/Write</P>
|
||||
*/
|
||||
public static final String COLUMN_DESCRIPTION = "description";
|
||||
|
||||
/**
|
||||
* The name of the column indicating whether the download was requesting through the public
|
||||
* API. This controls some differences in behavior.
|
||||
* <P>Type: BOOLEAN</P>
|
||||
* <P>Owner can Init/Read</P>
|
||||
*/
|
||||
public static final String COLUMN_IS_PUBLIC_API = "is_public_api";
|
||||
|
||||
/**
|
||||
* The name of the column holding a bitmask of allowed network types. This is only used for
|
||||
* public API downloads.
|
||||
* <P>Type: INTEGER</P>
|
||||
* <P>Owner can Init/Read</P>
|
||||
*/
|
||||
public static final String COLUMN_ALLOWED_NETWORK_TYPES = "allowed_network_types";
|
||||
|
||||
/**
|
||||
* The name of the column indicating whether roaming connections can be used. This is only
|
||||
* used for public API downloads.
|
||||
* <P>Type: BOOLEAN</P>
|
||||
* <P>Owner can Init/Read</P>
|
||||
*/
|
||||
public static final String COLUMN_ALLOW_ROAMING = "allow_roaming";
|
||||
|
||||
/**
|
||||
* The name of the column indicating whether metered connections can be used. This is only
|
||||
* used for public API downloads.
|
||||
* <P>Type: BOOLEAN</P>
|
||||
* <P>Owner can Init/Read</P>
|
||||
*/
|
||||
public static final String COLUMN_ALLOW_METERED = "allow_metered";
|
||||
|
||||
/**
|
||||
* Whether or not this download should be displayed in the system's Downloads UI. Defaults
|
||||
* to true.
|
||||
* <P>Type: INTEGER</P>
|
||||
* <P>Owner can Init/Read</P>
|
||||
*/
|
||||
public static final String COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI = "is_visible_in_downloads_ui";
|
||||
|
||||
/**
|
||||
* If true, the user has confirmed that this download can proceed over the mobile network
|
||||
* even though it exceeds the recommended maximum size.
|
||||
* <P>Type: BOOLEAN</P>
|
||||
*/
|
||||
public static final String COLUMN_BYPASS_RECOMMENDED_SIZE_LIMIT =
|
||||
"bypass_recommended_size_limit";
|
||||
|
||||
/**
|
||||
* Set to true if this download is deleted. It is completely removed from the database
|
||||
* when MediaProvider database also deletes the metadata asociated with this downloaded file.
|
||||
* <P>Type: BOOLEAN</P>
|
||||
* <P>Owner can Read</P>
|
||||
*/
|
||||
public static final String COLUMN_DELETED = "deleted";
|
||||
|
||||
/**
|
||||
* The URI to the corresponding entry in MediaProvider for this downloaded entry. It is
|
||||
* used to delete the entries from MediaProvider database when it is deleted from the
|
||||
* downloaded list.
|
||||
* <P>Type: TEXT</P>
|
||||
* <P>Owner can Read</P>
|
||||
*/
|
||||
public static final String COLUMN_MEDIAPROVIDER_URI = "mediaprovider_uri";
|
||||
|
||||
/**
|
||||
* The column that is used to remember whether the media scanner was invoked.
|
||||
* It can take the values: null or 0(not scanned), 1(scanned), 2 (not scannable).
|
||||
* <P>Type: TEXT</P>
|
||||
*/
|
||||
public static final String COLUMN_MEDIA_SCANNED = "scanned";
|
||||
|
||||
/**
|
||||
* The column with errorMsg for a failed downloaded.
|
||||
* Used only for debugging purposes.
|
||||
* <P>Type: TEXT</P>
|
||||
*/
|
||||
public static final String COLUMN_ERROR_MSG = "errorMsg";
|
||||
|
||||
/**
|
||||
* This column stores the source of the last update to this row.
|
||||
* This column is only for internal use.
|
||||
* Valid values are indicated by LAST_UPDATESRC_* constants.
|
||||
* <P>Type: INT</P>
|
||||
*/
|
||||
public static final String COLUMN_LAST_UPDATESRC = "lastUpdateSrc";
|
||||
|
||||
/**
|
||||
* default value for {@link #COLUMN_LAST_UPDATESRC}.
|
||||
* This value is used when this column's value is not relevant.
|
||||
*/
|
||||
public static final int LAST_UPDATESRC_NOT_RELEVANT = 0;
|
||||
|
||||
/**
|
||||
* One of the values taken by {@link #COLUMN_LAST_UPDATESRC}.
|
||||
* This value is used when the update is NOT to be relayed to the DownloadService
|
||||
* (and thus spare DownloadService from scanning the database when this change occurs)
|
||||
*/
|
||||
public static final int LAST_UPDATESRC_DONT_NOTIFY_DOWNLOADSVC = 1;
|
||||
|
||||
/*
|
||||
* Lists the destinations that an application can specify for a download.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This download will be saved to the external storage. This is the
|
||||
* default behavior, and should be used for any file that the user
|
||||
* can freely access, copy, delete. Even with that destination,
|
||||
* unencrypted DRM files are saved in secure internal storage.
|
||||
* Downloads to the external destination only write files for which
|
||||
* there is a registered handler. The resulting files are accessible
|
||||
* by filename to all applications.
|
||||
*/
|
||||
public static final int DESTINATION_EXTERNAL = 0;
|
||||
|
||||
/**
|
||||
* This download will be saved to the download manager's private
|
||||
* partition. This is the behavior used by applications that want to
|
||||
* download private files that are used and deleted soon after they
|
||||
* get downloaded. All file types are allowed, and only the initiating
|
||||
* application can access the file (indirectly through a content
|
||||
* provider). This requires the
|
||||
* android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED permission.
|
||||
*/
|
||||
public static final int DESTINATION_CACHE_PARTITION = 1;
|
||||
|
||||
/**
|
||||
* This download will be saved to the download manager's private
|
||||
* partition and will be purged as necessary to make space. This is
|
||||
* for private files (similar to CACHE_PARTITION) that aren't deleted
|
||||
* immediately after they are used, and are kept around by the download
|
||||
* manager as long as space is available.
|
||||
*/
|
||||
public static final int DESTINATION_CACHE_PARTITION_PURGEABLE = 2;
|
||||
|
||||
/**
|
||||
* This download will be saved to the download manager's private
|
||||
* partition, as with DESTINATION_CACHE_PARTITION, but the download
|
||||
* will not proceed if the user is on a roaming data connection.
|
||||
*/
|
||||
public static final int DESTINATION_CACHE_PARTITION_NOROAMING = 3;
|
||||
|
||||
/**
|
||||
* This download will be saved to the location given by the file URI in
|
||||
* {@link #COLUMN_FILE_NAME_HINT}.
|
||||
*/
|
||||
public static final int DESTINATION_FILE_URI = 4;
|
||||
|
||||
/**
|
||||
* This download will be saved to the system cache ("/cache")
|
||||
* partition. This option is only used by system apps and so it requires
|
||||
* android.permission.ACCESS_CACHE_FILESYSTEM permission.
|
||||
*/
|
||||
public static final int DESTINATION_SYSTEMCACHE_PARTITION = 5;
|
||||
|
||||
/**
|
||||
* This download was completed by the caller (i.e., NOT downloadmanager)
|
||||
* and caller wants to have this download displayed in Downloads App.
|
||||
*/
|
||||
public static final int DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD = 6;
|
||||
|
||||
/**
|
||||
* This download is allowed to run.
|
||||
*/
|
||||
public static final int CONTROL_RUN = 0;
|
||||
|
||||
/**
|
||||
* This download must pause at the first opportunity.
|
||||
*/
|
||||
public static final int CONTROL_PAUSED = 1;
|
||||
|
||||
/*
|
||||
* Lists the states that the download manager can set on a download
|
||||
* to notify applications of the download progress.
|
||||
* The codes follow the HTTP families:<br>
|
||||
* 1xx: informational<br>
|
||||
* 2xx: success<br>
|
||||
* 3xx: redirects (not used by the download manager)<br>
|
||||
* 4xx: client errors<br>
|
||||
* 5xx: server errors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns whether the status is informational (i.e. 1xx).
|
||||
*/
|
||||
public static boolean isStatusInformational(int status) {
|
||||
return (status >= 100 && status < 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the status is a success (i.e. 2xx).
|
||||
*/
|
||||
public static boolean isStatusSuccess(int status) {
|
||||
return (status >= 200 && status < 300);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the status is an error (i.e. 4xx or 5xx).
|
||||
*/
|
||||
public static boolean isStatusError(int status) {
|
||||
return (status >= 400 && status < 600);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the status is a client error (i.e. 4xx).
|
||||
*/
|
||||
public static boolean isStatusClientError(int status) {
|
||||
return (status >= 400 && status < 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the status is a server error (i.e. 5xx).
|
||||
*/
|
||||
public static boolean isStatusServerError(int status) {
|
||||
return (status >= 500 && status < 600);
|
||||
}
|
||||
|
||||
/**
|
||||
* this method determines if a notification should be displayed for a
|
||||
* given {@link #COLUMN_VISIBILITY} value
|
||||
*
|
||||
* @param visibility the value of {@link #COLUMN_VISIBILITY}.
|
||||
* @return true if the notification should be displayed. false otherwise.
|
||||
*/
|
||||
public static boolean isNotificationToBeDisplayed(int visibility) {
|
||||
return visibility == DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED ||
|
||||
visibility == DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the download has completed (either with success or
|
||||
* error).
|
||||
*/
|
||||
public static boolean isStatusCompleted(int status) {
|
||||
return (status >= 200 && status < 300) || (status >= 400 && status < 600);
|
||||
}
|
||||
|
||||
/**
|
||||
* This download hasn't stated yet
|
||||
*/
|
||||
public static final int STATUS_PENDING = 190;
|
||||
|
||||
/**
|
||||
* This download has started
|
||||
*/
|
||||
public static final int STATUS_RUNNING = 192;
|
||||
|
||||
/**
|
||||
* This download has been paused by the owning app.
|
||||
*/
|
||||
public static final int STATUS_PAUSED_BY_APP = 193;
|
||||
|
||||
/**
|
||||
* This download encountered some network error and is waiting before retrying the request.
|
||||
*/
|
||||
public static final int STATUS_WAITING_TO_RETRY = 194;
|
||||
|
||||
/**
|
||||
* This download is waiting for network connectivity to proceed.
|
||||
*/
|
||||
public static final int STATUS_WAITING_FOR_NETWORK = 195;
|
||||
|
||||
/**
|
||||
* This download exceeded a size limit for mobile networks and is waiting for a Wi-Fi
|
||||
* connection to proceed.
|
||||
*/
|
||||
public static final int STATUS_QUEUED_FOR_WIFI = 196;
|
||||
|
||||
/**
|
||||
* This download couldn't be completed due to insufficient storage
|
||||
* space. Typically, this is because the SD card is full.
|
||||
*/
|
||||
public static final int STATUS_INSUFFICIENT_SPACE_ERROR = 198;
|
||||
|
||||
/**
|
||||
* This download couldn't be completed because no external storage
|
||||
* device was found. Typically, this is because the SD card is not
|
||||
* mounted.
|
||||
*/
|
||||
public static final int STATUS_DEVICE_NOT_FOUND_ERROR = 199;
|
||||
|
||||
/**
|
||||
* This download has successfully completed.
|
||||
* Warning: there might be other status values that indicate success
|
||||
* in the future.
|
||||
* Use isSucccess() to capture the entire category.
|
||||
*/
|
||||
public static final int STATUS_SUCCESS = 200;
|
||||
|
||||
/**
|
||||
* This request couldn't be parsed. This is also used when processing
|
||||
* requests with unknown/unsupported URI schemes.
|
||||
*/
|
||||
public static final int STATUS_BAD_REQUEST = 400;
|
||||
|
||||
/**
|
||||
* This download can't be performed because the content type cannot be
|
||||
* handled.
|
||||
*/
|
||||
public static final int STATUS_NOT_ACCEPTABLE = 406;
|
||||
|
||||
/**
|
||||
* This download cannot be performed because the length cannot be
|
||||
* determined accurately. This is the code for the HTTP error "Length
|
||||
* Required", which is typically used when making requests that require
|
||||
* a content length but don't have one, and it is also used in the
|
||||
* client when a response is received whose length cannot be determined
|
||||
* accurately (therefore making it impossible to know when a download
|
||||
* completes).
|
||||
*/
|
||||
public static final int STATUS_LENGTH_REQUIRED = 411;
|
||||
|
||||
/**
|
||||
* This download was interrupted and cannot be resumed.
|
||||
* This is the code for the HTTP error "Precondition Failed", and it is
|
||||
* also used in situations where the client doesn't have an ETag at all.
|
||||
*/
|
||||
public static final int STATUS_PRECONDITION_FAILED = 412;
|
||||
|
||||
/**
|
||||
* The lowest-valued error status that is not an actual HTTP status code.
|
||||
*/
|
||||
public static final int MIN_ARTIFICIAL_ERROR_STATUS = 488;
|
||||
|
||||
/**
|
||||
* The requested destination file already exists.
|
||||
*/
|
||||
public static final int STATUS_FILE_ALREADY_EXISTS_ERROR = 488;
|
||||
|
||||
/**
|
||||
* Some possibly transient error occurred, but we can't resume the download.
|
||||
*/
|
||||
public static final int STATUS_CANNOT_RESUME = 489;
|
||||
|
||||
/**
|
||||
* This download was canceled
|
||||
*/
|
||||
public static final int STATUS_CANCELED = 490;
|
||||
|
||||
/**
|
||||
* This download has completed with an error.
|
||||
* Warning: there will be other status values that indicate errors in
|
||||
* the future. Use isStatusError() to capture the entire category.
|
||||
*/
|
||||
public static final int STATUS_UNKNOWN_ERROR = 491;
|
||||
|
||||
/**
|
||||
* This download couldn't be completed because of a storage issue.
|
||||
* Typically, that's because the filesystem is missing or full.
|
||||
* Use the more specific {@link #STATUS_INSUFFICIENT_SPACE_ERROR}
|
||||
* and {@link #STATUS_DEVICE_NOT_FOUND_ERROR} when appropriate.
|
||||
*/
|
||||
public static final int STATUS_FILE_ERROR = 492;
|
||||
|
||||
/**
|
||||
* This download couldn't be completed because of an HTTP
|
||||
* redirect response that the download manager couldn't
|
||||
* handle.
|
||||
*/
|
||||
public static final int STATUS_UNHANDLED_REDIRECT = 493;
|
||||
|
||||
/**
|
||||
* This download couldn't be completed because of an
|
||||
* unspecified unhandled HTTP code.
|
||||
*/
|
||||
public static final int STATUS_UNHANDLED_HTTP_CODE = 494;
|
||||
|
||||
/**
|
||||
* This download couldn't be completed because of an
|
||||
* error receiving or processing data at the HTTP level.
|
||||
*/
|
||||
public static final int STATUS_HTTP_DATA_ERROR = 495;
|
||||
|
||||
/**
|
||||
* This download couldn't be completed because of an
|
||||
* HttpException while setting up the request.
|
||||
*/
|
||||
public static final int STATUS_HTTP_EXCEPTION = 496;
|
||||
|
||||
/**
|
||||
* This download couldn't be completed because there were
|
||||
* too many redirects.
|
||||
*/
|
||||
public static final int STATUS_TOO_MANY_REDIRECTS = 497;
|
||||
|
||||
/**
|
||||
* This download has failed because requesting application has been
|
||||
* blocked by {@link NetworkPolicyManager}.
|
||||
*
|
||||
* @hide
|
||||
* @deprecated since behavior now uses
|
||||
* {@link #STATUS_WAITING_FOR_NETWORK}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final int STATUS_BLOCKED = 498;
|
||||
|
||||
/**
|
||||
* {@hide}
|
||||
*/
|
||||
public static String statusToString(int status) {
|
||||
switch (status) {
|
||||
case STATUS_PENDING:
|
||||
return "PENDING";
|
||||
case STATUS_RUNNING:
|
||||
return "RUNNING";
|
||||
case STATUS_PAUSED_BY_APP:
|
||||
return "PAUSED_BY_APP";
|
||||
case STATUS_WAITING_TO_RETRY:
|
||||
return "WAITING_TO_RETRY";
|
||||
case STATUS_WAITING_FOR_NETWORK:
|
||||
return "WAITING_FOR_NETWORK";
|
||||
case STATUS_QUEUED_FOR_WIFI:
|
||||
return "QUEUED_FOR_WIFI";
|
||||
case STATUS_INSUFFICIENT_SPACE_ERROR:
|
||||
return "INSUFFICIENT_SPACE_ERROR";
|
||||
case STATUS_DEVICE_NOT_FOUND_ERROR:
|
||||
return "DEVICE_NOT_FOUND_ERROR";
|
||||
case STATUS_SUCCESS:
|
||||
return "SUCCESS";
|
||||
case STATUS_BAD_REQUEST:
|
||||
return "BAD_REQUEST";
|
||||
case STATUS_NOT_ACCEPTABLE:
|
||||
return "NOT_ACCEPTABLE";
|
||||
case STATUS_LENGTH_REQUIRED:
|
||||
return "LENGTH_REQUIRED";
|
||||
case STATUS_PRECONDITION_FAILED:
|
||||
return "PRECONDITION_FAILED";
|
||||
case STATUS_FILE_ALREADY_EXISTS_ERROR:
|
||||
return "FILE_ALREADY_EXISTS_ERROR";
|
||||
case STATUS_CANNOT_RESUME:
|
||||
return "CANNOT_RESUME";
|
||||
case STATUS_CANCELED:
|
||||
return "CANCELED";
|
||||
case STATUS_UNKNOWN_ERROR:
|
||||
return "UNKNOWN_ERROR";
|
||||
case STATUS_FILE_ERROR:
|
||||
return "FILE_ERROR";
|
||||
case STATUS_UNHANDLED_REDIRECT:
|
||||
return "UNHANDLED_REDIRECT";
|
||||
case STATUS_UNHANDLED_HTTP_CODE:
|
||||
return "UNHANDLED_HTTP_CODE";
|
||||
case STATUS_HTTP_DATA_ERROR:
|
||||
return "HTTP_DATA_ERROR";
|
||||
case STATUS_HTTP_EXCEPTION:
|
||||
return "HTTP_EXCEPTION";
|
||||
case STATUS_TOO_MANY_REDIRECTS:
|
||||
return "TOO_MANY_REDIRECTS";
|
||||
case STATUS_BLOCKED:
|
||||
return "BLOCKED";
|
||||
default:
|
||||
return Integer.toString(status);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This download is visible but only shows in the notifications
|
||||
* while it's in progress.
|
||||
*/
|
||||
public static final int VISIBILITY_VISIBLE = DownloadManager.Request.VISIBILITY_VISIBLE;
|
||||
|
||||
/**
|
||||
* This download is visible and shows in the notifications while
|
||||
* in progress and after completion.
|
||||
*/
|
||||
public static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED =
|
||||
DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED;
|
||||
|
||||
/**
|
||||
* This download doesn't show in the UI or in the notifications.
|
||||
*/
|
||||
public static final int VISIBILITY_HIDDEN = DownloadManager.Request.VISIBILITY_HIDDEN;
|
||||
|
||||
/**
|
||||
* Constants related to HTTP request headers associated with each download.
|
||||
*/
|
||||
public static class RequestHeaders {
|
||||
public static final String HEADERS_DB_TABLE = "request_headers";
|
||||
public static final String COLUMN_DOWNLOAD_ID = "download_id";
|
||||
public static final String COLUMN_HEADER = "header";
|
||||
public static final String COLUMN_VALUE = "value";
|
||||
|
||||
/**
|
||||
* Path segment to add to a download URI to retrieve request headers
|
||||
*/
|
||||
public static final String URI_SEGMENT = "headers";
|
||||
|
||||
/**
|
||||
* Prefix for ContentValues keys that contain HTTP header lines, to be passed to
|
||||
* DownloadProvider.insert().
|
||||
*/
|
||||
public static final String INSERT_KEY_PREFIX = "http_header_";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query where clause for general querying.
|
||||
*/
|
||||
private static final String QUERY_WHERE_CLAUSE = Impl.COLUMN_NOTIFICATION_PACKAGE + "=? AND "
|
||||
+ Impl.COLUMN_NOTIFICATION_CLASS + "=?";
|
||||
|
||||
/**
|
||||
* Delete all the downloads for a package/class pair.
|
||||
*/
|
||||
public static final void removeAllDownloadsByPackage(
|
||||
Context context, String notification_package, String notification_class) {
|
||||
context.getContentResolver().delete(Impl.CONTENT_URI, QUERY_WHERE_CLAUSE,
|
||||
new String[]{notification_package, notification_class});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user