Android11已用内存达到80%时只弹出一次提示框

diff --git a/frameworks/base/core/res/res/layout/dialog_80.xml b/frameworks/base/core/res/res/layout/dialog_80.xml

new file mode 100755

index 00000000000..ccaf153c382

--- /dev/null

+++ b/frameworks/base/core/res/res/layout/dialog_80.xml

@@ -0,0 +1,26 @@

+

+http://schemas.android.com/apk/res/android"

+ android:layout_width="match_parent"

+ android:layout_height="wrap_content"

+ android:padding="10dp"

+ android:orientation="vertical">

+

+

+ android:id="@+id/tv_title"

+ android:layout_width="match_parent"

+ android:layout_height="wrap_content"

+ android:gravity="center_horizontal"

+ android:textStyle="bold"

+ android:textSize="18dp">

+

+

+

+ android:id="@+id/tv_content"

+ android:layout_marginTop="10dp"

+ android:layout_width="match_parent"

+ android:layout_height="wrap_content"

+ android:gravity="center_horizontal"

+ android:textSize="16dp">

+

+

+

\ No newline at end of file

diff --git a/frameworks/base/core/res/res/values/symbols.xml b/frameworks/base/core/res/res/values/symbols.xml

old mode 100644

new mode 100755

index ff6373b7d62..9f4a74a34a0

--- a/frameworks/base/core/res/res/values/symbols.xml

+++ b/frameworks/base/core/res/res/values/symbols.xml

@@ -251,6 +251,8 @@

+

+

@@ -1548,6 +1550,7 @@

+

diff --git a/frameworks/base/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java b/frameworks/base/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java

old mode 100644

new mode 100755

index 13e5a61a090..eda3943ca1e

--- a/frameworks/base/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java

+++ b/frameworks/base/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java

@@ -61,6 +61,22 @@ import java.io.PrintWriter;

import java.util.Objects;

import java.util.UUID;

import java.util.concurrent.atomic.AtomicInteger;

+//swl add

+import android.os.Looper;

+import com.android.internal.R;

+import android.content.IntentFilter;

+import android.os.Build;

+import android.os.Bundle;

+import android.app.AlertDialog;

+import android.content.DialogInterface;

+import android.view.WindowManager;

+import android.view.View.OnClickListener;

+import android.view.LayoutInflater;

+import android.widget.TextView;

+import android.view.View;

+import android.widget.Button;

+import android.util.Log;

+//end

/**

* Service that monitors and maintains free space on storage volumes.

@@ -71,6 +87,7 @@ import java.util.concurrent.atomic.AtomicInteger;

*/

public class DeviceStorageMonitorService extends SystemService {

private static final String TAG = "DeviceStorageMonitorService";

+ private static AlertDialog alertDialog;

/**

* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:

@@ -79,6 +96,7 @@ public class DeviceStorageMonitorService extends SystemService {

public static final String EXTRA_SEQUENCE = "seq";

private static final int MSG_CHECK = 1;

+ boolean FLAG_SHOWDIALOG_ONCE = true;

private static final long DEFAULT_LOG_DELTA_BYTES = DataUnit.MEBIBYTES.toBytes(64);

private static final long DEFAULT_CHECK_INTERVAL = DateUtils.MINUTE_IN_MILLIS;

@@ -211,6 +229,16 @@ public class DeviceStorageMonitorService extends SystemService {

// of any relevant broadcasts.

oldLevel = State.LEVEL_UNKNOWN;

newLevel = mForceLevel;

+ //swl add

+ } else if (usableBytes

+ Log.d("swl","start");

+ Log.d("swl","usableBytes + " + usableBytes);

+ Log.d("swl","totalBytes + " + totalBytes);

+ showDialog();

+ Log.d("swl","end");

+ FLAG_SHOWDIALOG_ONCE = false;

+ newLevel = State.LEVEL_FULL;

+ //end

} else if (usableBytes

newLevel = State.LEVEL_FULL;

} else if (usableBytes

@@ -258,6 +286,7 @@ public class DeviceStorageMonitorService extends SystemService {

switch (msg.what) {

case MSG_CHECK:

check();

+ Log.d("swl","DSMS");

return;

}

}

@@ -565,6 +594,45 @@ public class DeviceStorageMonitorService extends SystemService {

getContext().sendBroadcastAsUser(notFullIntent, UserHandle.ALL);

}

}

+ //swl add

+ public void showDialog(){

+ if(alertDialog != null && alertDialog.isShowing())

+ return;

+ AlertDialog.Builder b = new AlertDialog.Builder(getContext());

+ b.setCancelable(true);

+ View view = View.inflate(getContext(), com.android.internal.R.layout.dialog_80,null);

+ TextView titleTv = (TextView)view.findViewById(com.android.internal.R.id.tv_title);

+ titleTv.setText("Important Tip!");

+ TextView contentTv = (TextView)view.findViewById(com.android.internal.R.id.tv_content);

+ contentTv.setText("The device's memory has reached 80% of its capacity, free up space to guarantee the good performance of your product.");

+ b.setView(view);

+ final StorageManager storage0 = getContext().getSystemService(StorageManager.class);

+ Log.d("swl","showDialog");

+ //开启新的线程,防止弹出dialog时所依附的view未完成创建

+ new Thread(new Runnable(){

+ @Override

+ public void run() {

+ Looper.prepare();

+ try {

+ Thread.sleep(10000);

+ } catch (InterruptedException e) {

+ e.printStackTrace();

+ }

+ Log.d("swl", "1");

+ AlertDialog d = b.create();

+ Log.d("swl", "2");

+ d.setCanceledOnTouchOutside(true);

+ d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);//全局对话框

+ Log.d("swl", "3");

+ d.show();

+ alertDialog = d;

+ Log.d("swl", "内存不足");

+ Looper.loop();

+ }

+ }).start();

+

+}

+//end

private static class CacheFileDeletedObserver extends FileObserver {

public CacheFileDeletedObserver() {

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值