Messaging: Remove GServices

We don't have an actual implementation returning anything but the
defaults, so apply the defaults directly anywhere we need them

Change-Id: Ic651b4b13977799f2f4d2c702c430798fbff77f8
This commit is contained in:
Michael W
2024-12-15 15:50:57 +01:00
parent 7f22a3eea7
commit a2f67b4f7b
64 changed files with 91 additions and 3763 deletions

View File

@@ -17,304 +17,22 @@
package com.android.messaging.util;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Environment;
import android.telephony.SmsMessage;
import android.text.TextUtils;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
import com.android.messaging.Factory;
import com.android.messaging.R;
import com.android.messaging.datamodel.SyncManager;
import com.android.messaging.datamodel.action.DumpDatabaseAction;
import com.android.messaging.datamodel.action.LogTelephonyDatabaseAction;
import com.android.messaging.sms.MmsUtils;
import com.android.messaging.ui.UIIntents;
import com.android.messaging.ui.debug.DebugSmsMmsFromDumpFileDialogFragment;
import com.google.common.io.ByteStreams;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StreamCorruptedException;
public class DebugUtils {
private static final String TAG = "bugle.util.DebugUtils";
private static boolean sDebugNoise;
private static boolean sDebugClassZeroSms;
private static MediaPlayer [] sMediaPlayer;
private static final Object sLock = new Object();
public static final int DEBUG_SOUND_SERVER_REQUEST = 0;
public static final int DEBUG_SOUND_DB_OP = 1;
public static void maybePlayDebugNoise(final Context context, final int sound) {
if (sDebugNoise) {
synchronized (sLock) {
try {
if (sMediaPlayer == null) {
sMediaPlayer = new MediaPlayer[2];
sMediaPlayer[DEBUG_SOUND_SERVER_REQUEST] =
MediaPlayer.create(context, R.raw.server_request_debug);
sMediaPlayer[DEBUG_SOUND_DB_OP] =
MediaPlayer.create(context, R.raw.db_op_debug);
sMediaPlayer[DEBUG_SOUND_DB_OP].setVolume(1.0F, 1.0F);
sMediaPlayer[DEBUG_SOUND_SERVER_REQUEST].setVolume(0.3F, 0.3F);
}
if (sMediaPlayer[sound] != null) {
sMediaPlayer[sound].start();
}
} catch (final IllegalArgumentException e) {
LogUtil.e(TAG, "MediaPlayer exception", e);
} catch (final SecurityException e) {
LogUtil.e(TAG, "MediaPlayer exception", e);
} catch (final IllegalStateException e) {
LogUtil.e(TAG, "MediaPlayer exception", e);
}
}
}
}
public static boolean isDebugEnabled() {
return BugleGservices.get().getBoolean(BugleGservicesKeys.ENABLE_DEBUGGING_FEATURES,
BugleGservicesKeys.ENABLE_DEBUGGING_FEATURES_DEFAULT);
}
public abstract static class DebugAction {
final String mTitle;
public DebugAction(final String title) {
mTitle = title;
}
@NonNull
@Override
public String toString() {
return mTitle;
}
public abstract void run();
}
public static void showDebugOptions(final Activity host) {
final AlertDialog.Builder builder = new AlertDialog.Builder(host);
final ArrayAdapter<DebugAction> arrayAdapter = new ArrayAdapter<DebugAction>(
host, android.R.layout.simple_list_item_1);
arrayAdapter.add(new DebugAction("Dump Database") {
@Override
public void run() {
DumpDatabaseAction.dumpDatabase();
}
});
arrayAdapter.add(new DebugAction("Log Telephony Data") {
@Override
public void run() {
LogTelephonyDatabaseAction.dumpDatabase();
}
});
arrayAdapter.add(new DebugAction("Toggle Noise") {
@Override
public void run() {
sDebugNoise = !sDebugNoise;
}
});
arrayAdapter.add(new DebugAction("Force sync SMS") {
@Override
public void run() {
final BuglePrefs prefs = BuglePrefs.getApplicationPrefs();
prefs.putLong(BuglePrefsKeys.LAST_FULL_SYNC_TIME, -1);
SyncManager.forceSync();
}
});
arrayAdapter.add(new DebugAction("Sync SMS") {
@Override
public void run() {
SyncManager.sync();
}
});
arrayAdapter.add(new DebugAction("Load SMS/MMS from dump file") {
@Override
public void run() {
new DebugSmsMmsDumpTask(host,
DebugSmsMmsFromDumpFileDialogFragment.ACTION_LOAD).executeOnThreadPool();
}
});
arrayAdapter.add(new DebugAction("Email SMS/MMS dump file") {
@Override
public void run() {
new DebugSmsMmsDumpTask(host,
DebugSmsMmsFromDumpFileDialogFragment.ACTION_EMAIL).executeOnThreadPool();
}
});
arrayAdapter.add(new DebugAction("MMS Config...") {
@Override
public void run() {
UIIntents.get().launchDebugMmsConfigActivity(host);
}
});
arrayAdapter.add(new DebugAction(sDebugClassZeroSms ? "Turn off Class 0 sms test" :
"Turn on Class Zero test") {
@Override
public void run() {
sDebugClassZeroSms = !sDebugClassZeroSms;
}
});
arrayAdapter.add(new DebugAction("Test sharing a file URI") {
@Override
public void run() {
shareFileUri();
}
});
builder.setAdapter(arrayAdapter, (arg0, pos) -> arrayAdapter.getItem(pos).run());
builder.create().show();
}
/**
* Task to list all the dump files and perform an action on it
*/
private static class DebugSmsMmsDumpTask extends SafeAsyncTask<Void, Void, String[]> {
private final String mAction;
private final Activity mHost;
public DebugSmsMmsDumpTask(final Activity host, final String action) {
mHost = host;
mAction = action;
}
@Override
protected void onPostExecute(final String[] result) {
if (result == null || result.length < 1) {
return;
}
final FragmentManager fragmentManager = mHost.getFragmentManager();
final FragmentTransaction ft = fragmentManager.beginTransaction();
final DebugSmsMmsFromDumpFileDialogFragment dialog =
DebugSmsMmsFromDumpFileDialogFragment.newInstance(result, mAction);
dialog.show(fragmentManager, ""/*tag*/);
}
@Override
protected String[] doInBackgroundTimed(final Void... params) {
final File dir = DebugUtils.getDebugFilesDir();
return dir.list((dir1, filename) -> filename != null
&& ((mAction == DebugSmsMmsFromDumpFileDialogFragment.ACTION_EMAIL
&& filename.equals(DumpDatabaseAction.DUMP_NAME))
|| filename.startsWith(MmsUtils.MMS_DUMP_PREFIX)
|| filename.startsWith(MmsUtils.SMS_DUMP_PREFIX)));
}
}
/**
* Dump the received raw SMS data into a file on external storage
*
* @param id The ID to use as part of the dump file name
* @param messages The raw SMS data
*/
public static void dumpSms(final long id, final android.telephony.SmsMessage[] messages,
final String format) {
try {
final String dumpFileName = MmsUtils.SMS_DUMP_PREFIX + id;
final File dumpFile = DebugUtils.getDebugFile(dumpFileName, true);
if (dumpFile != null) {
final FileOutputStream fos = new FileOutputStream(dumpFile);
final DataOutputStream dos = new DataOutputStream(fos);
try {
final int chars = (TextUtils.isEmpty(format) ? 0 : format.length());
dos.writeInt(chars);
if (chars > 0) {
dos.writeUTF(format);
}
dos.writeInt(messages.length);
for (final android.telephony.SmsMessage message : messages) {
final byte[] pdu = message.getPdu();
dos.writeInt(pdu.length);
dos.write(pdu, 0, pdu.length);
}
dos.flush();
} finally {
dos.close();
ensureReadable(dumpFile);
}
}
} catch (final IOException e) {
LogUtil.e(LogUtil.BUGLE_TAG, "dumpSms: " + e, e);
}
}
/**
* Load MMS/SMS from the dump file
*/
public static SmsMessage[] retreiveSmsFromDumpFile(final String dumpFileName) {
SmsMessage[] messages = null;
final File inputFile = DebugUtils.getDebugFile(dumpFileName, false);
if (inputFile != null) {
FileInputStream fis = null;
DataInputStream dis = null;
try {
fis = new FileInputStream(inputFile);
dis = new DataInputStream(fis);
// SMS dump
String format = null;
final int chars = dis.readInt();
if (chars > 0) {
format = dis.readUTF();
}
final int count = dis.readInt();
final SmsMessage[] messagesTemp = new SmsMessage[count];
for (int i = 0; i < count; i++) {
final int length = dis.readInt();
final byte[] pdu = new byte[length];
dis.read(pdu, 0, length);
messagesTemp[i] = SmsMessage.createFromPdu(pdu, format);
}
messages = messagesTemp;
} catch (final FileNotFoundException e) {
// Nothing to do
} catch (final StreamCorruptedException e) {
// Nothing to do
} catch (final IOException e) {
// Nothing to do
} finally {
if (dis != null) {
try {
dis.close();
} catch (final IOException e) {
// Nothing to do
}
}
}
}
return messages;
}
public static File getDebugFile(final String fileName, final boolean create) {
final File dir = getDebugFilesDir();
final File file = new File(dir, fileName);
@@ -416,24 +134,4 @@ public class DebugUtils {
// Never found ourself in the stack?!
return null;
}
/**
* Returns a boolean indicating whether ClassZero debugging is enabled. If enabled, any received
* sms is treated as if it were a class zero message and displayed by the ClassZeroActivity.
*/
public static boolean debugClassZeroSmsEnabled() {
return sDebugClassZeroSms;
}
/** Shares a ringtone file via file URI. */
private static void shareFileUri() {
final String packageName = "com.android.messaging";
final String fileName = "/system/media/audio/ringtones/Andromeda.ogg";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setPackage(packageName);
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + fileName));
intent.setType("image/*");
Factory.get().getApplicationContext().startActivity(intent);
}
}