nt-fwk: create stub for NtOnlineConfig

* Required by nothing camera app
* Part of Nt-framework on stock
This commit is contained in:
aswin7469
2025-08-04 18:38:27 +05:30
committed by nyxalune
parent 9474c46db8
commit a59d5fc9a4
5 changed files with 176 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
package com.nothing.ext;
import android.content.ContentResolver;
import android.database.ContentObserver;
import org.json.JSONArray;
public interface INtOnlineConfig {
public static final INtOnlineConfig DEFAULT = new INtOnlineConfig() {};
default JSONArray grabConfig(ContentResolver resolver, String projectName) {
return null;
}
default void registerContentObserver(ContentResolver resolver, String projectName, boolean notifyForDescendants, ContentObserver observer) {
}
}

View File

@@ -0,0 +1,35 @@
package com.nothing.onlineconfig;
import android.content.Context;
import android.util.Log;
import org.json.JSONArray;
/**
* A stub for the com.nothing.onlineconfig.ConfigGrabber class.
* The original application uses reflection to instantiate this class,
* and the constructor was likely causing a crash. This stub provides a
* safe, non-functional implementation that will be found by the reflection
* code and will not crash.
*/
public class ConfigGrabber {
private static final String TAG = "ConfigGrabberStub";
// The original constructor likely took a Context and a String.
// We must match this signature for the reflection call to succeed.
public ConfigGrabber(Context context, String projectName) {
Log.d(TAG, "ConfigGrabber stub created for project: " + projectName);
// The original constructor would have been the source of the crash.
// We've replaced it with this safe, no-op implementation.
}
/**
* Stubs the grabConfig method to return an empty JSONArray.
* This prevents any dependent code from processing a null or invalid config.
*
* @return An empty JSONArray.
*/
public JSONArray grabConfig() {
Log.d(TAG, "grabConfig() called on stub. Returning an empty JSONArray.");
return new JSONArray();
}
}

View File

@@ -0,0 +1,43 @@
package com.nothing.onlineconfig;
import android.content.Context;
import android.database.ContentObserver;
import android.os.Handler;
import android.util.Log;
import org.json.JSONArray;
public class ConfigObserver extends ContentObserver {
private static final String TAG = "ConfigObserverStub";
public interface ConfigUpdater {
void updateConfig(JSONArray jSONArray);
}
// A dependency on ConfigGrabber, which we now have a stub for.
private final ConfigGrabber mConfigGrabber;
private final ConfigUpdater mConfigUpdater;
public ConfigObserver(Context context, Handler handler, ConfigUpdater configUpdater, String projectName) {
super(handler);
Log.d(TAG, "ConfigObserver stub created.");
this.mConfigGrabber = new ConfigGrabber(context, projectName);
this.mConfigUpdater = configUpdater;
}
public void register() {
Log.d(TAG, "register() called on stub. No-op.");
}
public void unregister() {
Log.d(TAG, "unregister() called on stub. No-op.");
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.d(TAG, "onChange() called on stub. Notifying updater with empty config.");
if (mConfigUpdater != null) {
mConfigUpdater.updateConfig(mConfigGrabber.grabConfig());
}
}
}

View File

@@ -0,0 +1,26 @@
package com.nothing.onlineconfig;
import android.content.ContentResolver;
import android.database.ContentObserver;
import android.util.Log;
import com.nothing.ext.INtOnlineConfig;
import org.json.JSONArray;
public class NtOnlineConfigImpl implements INtOnlineConfig {
private static final String TAG = "NtOnlineConfigImplStub";
public NtOnlineConfigImpl() {
Log.d(TAG, "NtOnlineConfigImpl stub created.");
}
@Override
public JSONArray grabConfig(ContentResolver resolver, String projectName) {
Log.d(TAG, "grabConfig() called on stub. Returning an empty array.");
return new JSONArray();
}
@Override
public void registerContentObserver(ContentResolver resolver, String projectName, boolean notifyForDescendants, ContentObserver observer) {
Log.d(TAG, "registerContentObserver() called on stub. No-op.");
}
}

View File

@@ -0,0 +1,56 @@
package com.nothing.sdk.onlineconfig;
import android.content.Context;
import android.database.ContentObserver;
import android.os.Handler;
import android.util.Log;
import org.json.JSONArray;
import com.nothing.onlineconfig.NtOnlineConfigImpl;
/**
* A stub for the ConfigObserver class, located in the com.nothing.sdk.onlineconfig package.
* This class is the direct cause of the crash, as indicated by the logcat. This stub
* provides a non-functional, safe implementation to prevent the app from crashing.
*/
public class ConfigObserver extends ContentObserver {
private static final String TAG = "ConfigObserverStub";
public interface ConfigUpdater {
void updateConfig(JSONArray jSONArray);
}
// A simple stub for the ConfigGrabber dependency
private static class ConfigGrabberStub {
public ConfigGrabberStub(Context context, String projectName) {}
public JSONArray grabConfig() { return new JSONArray(); }
}
private final ConfigGrabberStub mConfigGrabber;
private final ConfigUpdater mConfigUpdater;
public ConfigObserver(Context context, Handler handler, ConfigUpdater configUpdater, String projectName) {
super(handler);
Log.d(TAG, "ConfigObserver stub created. This should prevent the crash.");
// We create a local stub for ConfigGrabber to avoid dependencies on other stubs.
this.mConfigGrabber = new ConfigGrabberStub(context, projectName);
this.mConfigUpdater = configUpdater;
// The original code here is likely the source of the crash. We are bypassing it.
}
public void register() {
Log.d(TAG, "register() called on stub. No-op.");
}
public void unregister() {
Log.d(TAG, "unregister() called on stub. No-op.");
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.d(TAG, "onChange() called on stub. Notifying updater with empty config.");
if (mConfigUpdater != null) {
mConfigUpdater.updateConfig(mConfigGrabber.grabConfig());
}
}
}