package com.sjm.sjmdsp.net.download; import android.app.DownloadManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.database.Cursor; import android.net.Uri; import android.os.Build; import android.os.Environment; import androidx.core.content.FileProvider; import com.ss.android.downloadad.api.constant.AdBaseConstants; import java.io.File; import java.io.IOException; public class DownloadItem { private long downloadId; private DownloadManager downloadManager; private Context mContext; private String name; private String pathstr; private BroadcastReceiver receiver = new BroadcastReceiver() { /* class com.sjm.sjmdsp.net.download.DownloadItem.AnonymousClass1 */ public void onReceive(Context context, Intent intent) { DownloadItem.this.checkStatus(); } }; public DownloadItem(Context context, String str, String str2) { this.mContext = context; downloadAPK(str, str2); this.name = str2; } private void downloadAPK(String str, String str2) { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(str)); request.setAllowedOverRoaming(false); request.setNotificationVisibility(0); request.setTitle("通知标题,随意修改"); request.setDescription("新版***下载中..."); request.setVisibleInDownloadsUi(true); File file = new File(this.mContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), str2); request.setDestinationUri(Uri.fromFile(file)); this.pathstr = file.getAbsolutePath(); if (this.downloadManager == null) { this.downloadManager = (DownloadManager) this.mContext.getSystemService("download"); } DownloadManager downloadManager2 = this.downloadManager; if (downloadManager2 != null) { this.downloadId = downloadManager2.enqueue(request); } this.mContext.registerReceiver(this.receiver, new IntentFilter("android.intent.action.DOWNLOAD_COMPLETE")); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void checkStatus() { DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(this.downloadId); Cursor query2 = this.downloadManager.query(query); if (query2.moveToFirst()) { int i = query2.getInt(query2.getColumnIndex("status")); if (i == 8) { installAPK(); query2.close(); } else if (i == 16) { query2.close(); this.mContext.unregisterReceiver(this.receiver); } } } private void installAPK() { setPermission(this.pathstr); Intent intent = new Intent("android.intent.action.VIEW"); intent.setFlags(268435456); if (Build.VERSION.SDK_INT >= 24) { Uri uriForFile = FileProvider.getUriForFile(this.mContext, "com.lxtwsw.weather.fileprovider", new File(this.pathstr)); intent.addFlags(1); intent.setDataAndType(uriForFile, AdBaseConstants.MIME_APK); } else { intent.setDataAndType(Uri.fromFile(new File(Environment.DIRECTORY_DOWNLOADS, this.name)), AdBaseConstants.MIME_APK); } this.mContext.startActivity(intent); } private void setPermission(String str) { try { Runtime.getRuntime().exec("chmod 777 " + str); } catch (IOException e) { e.printStackTrace(); } } }