Skip to content

Commit 73406be

Browse files
Pragnya Paramitazwliew
authored andcommitted
frameworks/base: Addition of Changes for ZeroBalance feature
--Addition of code to receive broadcast from ZeroBalanceHelper application for executing command to write block/unblock rule to Iptable. --Addition of ZeroBalanceHelper file to be accesible by other modules to notify ZeroBalanceHelper application about update on change of SIM balance. --Addition of rule to allow browser uid when rest all applications are in blocked state. --Addition of feature flag to control the zerobalance feature. CRs-Fixed: 927258 Change-Id: Ifdf4c46fd63ab78193047a9bc8b62bf41065a665
1 parent c15736b commit 73406be

4 files changed

Lines changed: 144 additions & 0 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
** Copyright (c) 2015, The Linux Foundation. All rights reserved.
3+
4+
** Redistribution and use in source and binary forms, with or without
5+
** modification, are permitted provided that the following conditions are
6+
** met:
7+
** * Redistributions of source code must retain the above copyright
8+
** notice, this list of conditions and the following disclaimer.
9+
** * Redistributions in binary form must reproduce the above
10+
** copyright notice, this list of conditions and the following
11+
** disclaimer in the documentation and/or other materials provided
12+
** with the distribution.
13+
** * Neither the name of The Linux Foundation nor the names of its
14+
** contributors may be used to endorse or promote products derived
15+
** from this software without specific prior written permission.
16+
17+
** THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18+
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19+
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20+
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21+
** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24+
** BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25+
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26+
** OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27+
** IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
package android.net;
31+
32+
import android.app.ActivityThread;
33+
import android.content.Context;
34+
import android.content.Intent;
35+
import android.os.SystemProperties;
36+
import android.os.UserHandle;
37+
import android.util.Log;
38+
39+
import com.android.internal.R;
40+
41+
/** @hide */
42+
public final class ZeroBalanceHelper {
43+
44+
public static final String BACKGROUND_DATA_PROPERTY = "sys.background.data.disable";
45+
public static final String BACKGROUND_DATA_BROADCAST = "org.codeaurora.background.data";
46+
public static final String TAG = "ZeroBalance";
47+
48+
private static int sRedirectCount = 0;
49+
private static int sRedirectMaxCount = 3;
50+
51+
private Context mContext = null;
52+
53+
public ZeroBalanceHelper() {
54+
mContext = ActivityThread.currentApplication();
55+
}
56+
57+
public void setBgDataProperty(String enabled) {
58+
Intent intent = new Intent();
59+
intent.setAction(BACKGROUND_DATA_BROADCAST);
60+
intent.putExtra("enabled", enabled);
61+
mContext.sendBroadcast(intent);
62+
}
63+
64+
public String getBgDataProperty() {
65+
String isBgDataPropertySet = SystemProperties.get(BACKGROUND_DATA_PROPERTY, "false");
66+
if (Boolean.parseBoolean(isBgDataPropertySet)) {
67+
sRedirectCount = 0;
68+
}
69+
return isBgDataPropertySet;
70+
}
71+
72+
private String getConfiguredRedirectURL() {
73+
String redirectURL = mContext.getResources().getString(
74+
com.android.internal.R.string.operator_config_url);
75+
Log.d(TAG, "Returning the configured redirect URL : "
76+
+ redirectURL);
77+
return redirectURL;
78+
}
79+
80+
public synchronized void setHttpRedirectCount(String url) {
81+
String redirectUrl = getConfiguredRedirectURL();
82+
if (redirectUrl != null && url.contains(redirectUrl)) {
83+
sRedirectCount++;
84+
Log.d(TAG, "http:sRedirectCount="+sRedirectCount);
85+
if (sRedirectCount >= sRedirectMaxCount) {
86+
Log.d(TAG,"http:Background Data will be disabled" );
87+
setBgDataProperty("true");
88+
sRedirectCount = 0;
89+
}
90+
} else {
91+
Log.d(TAG,"http: resetting the counter ");
92+
sRedirectCount = 0;
93+
}
94+
}
95+
96+
public boolean getFeatureConfigValue() {
97+
return mContext.getResources().getBoolean(R.bool.config_zero_balance_operator);
98+
}
99+
}

core/res/res/values/config.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,4 +2598,10 @@
25982598
<integer-array translatable="false" name="config_deviceLightCapabilities">
25992599
</integer-array>
26002600

2601+
<!-- Zero Balance redirect URL config -->
2602+
<string name="operator_config_url" translatable="false"></string>
2603+
<!-- Zero Balance ping URL config -->
2604+
<string name="operator_ping_url" translatable="false"></string>
2605+
<!-- Zero Balance feature enable config -->
2606+
<bool name="config_zero_balance_operator">false</bool>
26012607
</resources>

core/res/res/values/symbols.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,4 +2418,8 @@
24182418
<java-symbol type="string" name="config_packagedKeyboardName" />
24192419

24202420
<java-symbol type="bool" name="config_useSystemClockforRotationSensor" />
2421+
2422+
<java-symbol type="string" name="operator_config_url" />
2423+
<java-symbol type="string" name="operator_ping_url" />
2424+
<java-symbol type="bool" name="config_zero_balance_operator"/>
24212425
</resources>

services/core/java/com/android/server/NetworkManagementService.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646

4747
import android.annotation.NonNull;
4848
import android.app.ActivityManagerNative;
49+
import android.content.BroadcastReceiver;
4950
import android.content.Context;
51+
import android.content.Intent;
52+
import android.content.IntentFilter;
5053
import android.net.ConnectivityManager;
5154
import android.net.INetworkManagementEventObserver;
5255
import android.net.InterfaceConfiguration;
@@ -84,6 +87,7 @@
8487
import android.util.SparseBooleanArray;
8588
import android.util.SparseIntArray;
8689

90+
import com.android.internal.R;
8791
import com.android.internal.annotations.GuardedBy;
8892
import com.android.internal.app.IBatteryStats;
8993
import com.android.internal.net.NetworkStatsFactory;
@@ -332,6 +336,12 @@ public static NetworkManagementService create(Context context) throws Interrupte
332336

333337
public void systemReady() {
334338
prepareNativeDaemon();
339+
// Register the receiver for Zerobalance blocking/unblocking
340+
if (mContext.getResources().getBoolean(R.bool.config_zero_balance_operator)) {
341+
final IntentFilter restrictFilter = new IntentFilter();
342+
restrictFilter.addAction("org.codeaurora.restrictData");
343+
mContext.registerReceiver(mZeroBalanceReceiver, restrictFilter);
344+
}
335345
if (DBG) Slog.d(TAG, "Prepared");
336346
}
337347

@@ -2674,4 +2684,29 @@ private void initDataInterface() {
26742684
mDataInterfaceName = linkProperties.getInterfaceName();
26752685
}
26762686
}
2687+
2688+
private BroadcastReceiver mZeroBalanceReceiver = new BroadcastReceiver() {
2689+
@Override
2690+
public void onReceive(Context context, Intent intent) {
2691+
boolean isBlockAllData = false;
2692+
if (intent != null
2693+
&& intent.getAction().equals("org.codeaurora.restrictData")) {
2694+
isBlockAllData = intent.getBooleanExtra("Restrict", false);
2695+
Log.wtf("ZeroBalance", "Intent value to block unblock data" + isBlockAllData);
2696+
}
2697+
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
2698+
2699+
// Silently discard when control disabled
2700+
// TODO: Eventually migrate to always be enabled
2701+
if (!mBandwidthControlEnabled) return;
2702+
try {
2703+
Log.wtf("ZeroBalance", "before calling connector Intent"
2704+
+ "value to block unblock data" + isBlockAllData);
2705+
mConnector.execute("bandwidth",
2706+
isBlockAllData ? "blockAllData" : "unblockAllData");
2707+
} catch (NativeDaemonConnectorException e) {
2708+
throw e.rethrowAsParcelableException();
2709+
}
2710+
}
2711+
};
26772712
}

0 commit comments

Comments
 (0)