Move Ethernet related files to f/b/packages/ConnectivityT.

ethernet-service is going to be moved into Connectivity mainline module.
Notice that below sources are also only used in the ethernet framework
during compiling the filegroup: framework-connectivity-ethernet-sources.
Move them from f/b to f/b/packages/ConnectivityT as well.

Ethernet framework only related files:
    - IInternalNetworkManagementListener.aidl
    - InternalNetworkManagementException.java
    - InternalNetworkManagementException.aidl
    - InternalNetworkUpdateRequest.java
    - InternalNetworkUpdateRequest.aidl

Ethernet service only related files:
    - DelayedDiskWrite.java(IpConfigStore imports this class)

Bug: 210586283
Test: build pass
      atest FrameworksNetTests
      atest EthernetServiceTests
Change-Id: I1ec2d1d182c04f3f2acc9b757d5061ca749a4a3c
This commit is contained in:
Xiao Ma
2021-12-28 06:33:23 +00:00
parent e5c3fce077
commit e3da3eb78b
7 changed files with 25 additions and 3 deletions

View File

@@ -66,6 +66,7 @@ filegroup {
filegroup {
name: "services.connectivity-ethernet-sources",
srcs: [
"src/com/android/server/net/DelayedDiskWrite.java",
"src/com/android/server/net/IpConfigStore.java",
],
path: "src",

View File

@@ -0,0 +1,114 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.server.net;
import android.os.Handler;
import android.os.HandlerThread;
import android.text.TextUtils;
import android.util.Log;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* This class provides APIs to do a delayed data write to a given {@link OutputStream}.
*/
public class DelayedDiskWrite {
private static final String TAG = "DelayedDiskWrite";
private HandlerThread mDiskWriteHandlerThread;
private Handler mDiskWriteHandler;
/* Tracks multiple writes on the same thread */
private int mWriteSequence = 0;
/**
* Used to do a delayed data write to a given {@link OutputStream}.
*/
public interface Writer {
/**
* write data to a given {@link OutputStream}.
*/
void onWriteCalled(DataOutputStream out) throws IOException;
}
/**
* Do a delayed data write to a given output stream opened from filePath.
*/
public void write(final String filePath, final Writer w) {
write(filePath, w, true);
}
/**
* Do a delayed data write to a given output stream opened from filePath.
*/
public void write(final String filePath, final Writer w, final boolean open) {
if (TextUtils.isEmpty(filePath)) {
throw new IllegalArgumentException("empty file path");
}
/* Do a delayed write to disk on a separate handler thread */
synchronized (this) {
if (++mWriteSequence == 1) {
mDiskWriteHandlerThread = new HandlerThread("DelayedDiskWriteThread");
mDiskWriteHandlerThread.start();
mDiskWriteHandler = new Handler(mDiskWriteHandlerThread.getLooper());
}
}
mDiskWriteHandler.post(new Runnable() {
@Override
public void run() {
doWrite(filePath, w, open);
}
});
}
private void doWrite(String filePath, Writer w, boolean open) {
DataOutputStream out = null;
try {
if (open) {
out = new DataOutputStream(new BufferedOutputStream(
new FileOutputStream(filePath)));
}
w.onWriteCalled(out);
} catch (IOException e) {
loge("Error writing data file " + filePath);
} finally {
if (out != null) {
try {
out.close();
} catch (Exception e) { }
}
// Quit if no more writes sent
synchronized (this) {
if (--mWriteSequence == 0) {
mDiskWriteHandler.getLooper().quit();
mDiskWriteHandler = null;
mDiskWriteHandlerThread = null;
}
}
}
}
private void loge(String s) {
Log.e(TAG, s);
}
}